Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #9793] Add Style/QuotedSymbols to enforce consistency in quoted symbols #9809

Merged
merged 2 commits into from May 19, 2021

Conversation

dvandersluis
Copy link
Member

@dvandersluis dvandersluis commented May 17, 2021

Like Style/StringLiterals, this cop checks for the quoting style for symbols to be consistent. Checking whether a symbol should be quoted or not is still handled by Lint/SymbolConversion.

This cop shares as much as possible with Style/StringLiterals for ease of maintainabilty. As well, for simple configuration, the default "style" is same_as_string_literals which will automatically apply the same configuration set up for Style/StringLiterals to this cop as well (it defaults to single_quotes if StringLiterals is not enabled).

Additionally, Lint/SymbolConversion no longer tries to figure out what quote type to use from Style/StringLiterals' configuration. Instead, it always inserts a double quote (since that's always "safe"), and allows this new cop to handle the quoting.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

…n quoted symbols.

Like `Style/StringLiterals`, this cop checks for the quoting style for symbols to be consistent. Checking whether a symbol _should_ be quoted or not is still handled by `Lint/SymbolConversion`.

This cop shares as much as possible with `Style/StringLiterals` for ease of maintainabilty. As well, for simple configuration, the default "style" is `same_as_string_literals` which will automatically apply the same configuration set up for `Style/StringLiterals` to this cop as well (it defaults to `single_quotes` if `StringLiterals` is not enabled).
…e `Style/QuotedSymbols` can now correct those to the correct quotes as per configuration.
Copy link
Collaborator

@bbatsov bbatsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! 🚀

@dvandersluis dvandersluis merged commit d54855f into rubocop:master May 19, 2021
@dvandersluis dvandersluis deleted the issue/9793 branch May 19, 2021 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should Style/StringLiterals also apply to quoted symbols?
2 participants