Andrew Grimm
Andrew Grimm

Reputation: 81590

Make Rails generate single quote strings rather than double quote strings to satisfy RuboCop

How can I make Rails generate single quoted strings rather than double quoted strings when it generates code, such as migrations?

I'm not too fussed about what kind of strings are used in migrations, but it causes complications for RuboCop. The only way I can envisage RuboCop ignoring it is if I explicitly tell it to ignore the offending files, or to not enforce the Style/StringLiterals cop at all.

Upvotes: 6

Views: 1758

Answers (1)

I think you shouldn't be checking style in autogenerated files, as you are not really writing them. I would exclude files such as db/data_schema.rb in your rubocop.yml file.

AllCops:
  Exclude:
    - 'db/schema.rb'

The files in db/migrate/ are not really autogenerated as you also can write your own migrations. You could exclude Style/StringLiterals only for migrations in your rubocop.yml file:

Style/StringLiterals:
  Exclude:
    - 'db/migrate/*'

You can also run rubocop auto-correction after generating the migration, as Rubocop can efficiently correct Style/StringLiterals offenses:

rubocop -a

Upvotes: 6

Related Questions