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 #9621] Add consistent style to Lint/SymbolConversion to require all symbol keys in a hash to use the same convention #9623

Merged
merged 1 commit into from Mar 22, 2021

Conversation

dvandersluis
Copy link
Member

The consistent style works the same as the previous default style (now called strict), in that symbol conversions should be explicit. However, in the case of a hash with a mix of symbol keys requiring quoting and not, this style now enforces that all keys are quoted for consistency.

Fixes #9621.


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.

@dvandersluis
Copy link
Member Author

@rubocop/rubocop-core one thing that I'm not sure about is that Lint cops generally do not have configurable styles; Lint/InheritException is the only other one. However, this behaviour can't be enforced by a separate Style cop unless Lint/SymbolConversion is updated to ignore some cases if that cop is enabled, which is another can of worms. Maybe someone has an idea?

Separately, I am using the configuration from Style/StringLiterals to determine how to quote the keys. We don't currently have anything checking for consistency of quote style in quoted symbol literals.

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 21, 2021

@rubocop/rubocop-core one thing that I'm not sure about is that Lint cops generally do not have configurable styles; Lint/InheritException is the only other one. However, this behaviour can't be enforced by a separate Style cop unless Lint/SymbolConversion is updated to ignore some cases if that cop is enabled, which is another can of worms. Maybe someone has an idea?

Most Lint cops shouldn't have different supported styles, but I guess that's OK in the current situation. Alternatively this can also be some flag like "AllowConsistentSymbolsInHash" or something along those lines. I'm fine with the current approach as well.

Separately, I am using the configuration from Style/StringLiterals to determine how to quote the keys. We don't currently have anything checking for consistency of quote style in quoted symbol literals.

I think that's fine.

@@ -21,10 +27,26 @@ module Lint
# :underscored_symbol
# :'hyphenated-string'
#
# @example EnforcedStyle: consistent
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be a good idea to add the strict case for hashes as well, so it's clearer what this means for them.

Copy link
Member Author

Choose a reason for hiding this comment

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

@bbatsov I added additional documentation, thanks!

…to require all symbol keys in a hash to use the same convention.

The `consistent` style works the same as the previous default style (now called `strict`), in that symbol conversions should be explicit. However, in the case of a hash with a mix of symbol keys requiring quoting and not, this style now enforces that all keys are quoted for consistency.
@bbatsov bbatsov merged commit 5125284 into rubocop:master Mar 22, 2021
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 22, 2021

Thanks!

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.

Lint/SymbolConversion to provide an additional "consistent" option
3 participants