Skip to content

Enable Style/StringLiterals cop with `double_quotes` value

Description

Our codebase now has mixed quotes used for lines: single quotes and double ones.

That brings some inconsistency, makes code a little bit harder to understand (why are we using double quotes at this place while on the lines above/below there are single ones? Does it mean we are missing some interpolation here?).

Moreover, there are MRs when some reviewers ask community contributors to change quotes from single to double or vice versa a few times, so an MR gets more time to be edited, updated, and merged. And more pipelines gets run for every push with such changes.

Proposal

My proposal is quite simple. Let's get rid of inconsistency. Just use double quotes everywhere where it's possible.

No need to synchronize quotes with already existing ones in a file.
No need to stop and think if I want to add an interpolation to a string (if yes, I should use double quotes. If not, single ones) - just use double quotes and that's it.

Double quotes do not have performance penalty over single quotes.

Since there are over 20 000 strings with single quotes in codebase, I propose these steps:

  1. Enable lint
Style/StringLiterals:
  Enabled: true
  EnforcedStyle: double_quotes
  # If `true`, strings which span multiple lines using `\` for continuation must
  # use the same type of quotes on each line.
  ConsistentQuotesInMultiline: false

That will prevent adding new single quoted lines.

  1. Run rubocop with --auto-gen-config to update current .rubocop-todo.yml with found single quoted lines. Rubocop will still be green on existing strings.
  2. Run rubocop with --auto-correct on files from the todo list above. No more that 500 files should be changed per a MR because it's going to be quite hard to review changes if there are too many files.

So by ~20 MRs all the lines will be fixed.