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

Include expanded EnforcedStyle options when --no-auto-gen-enforced-style is given #12388

Conversation

kpost
Copy link
Contributor

@kpost kpost commented Nov 14, 2023

It seems to me that when the --no-auto-gen-enforced-style is given, not only EnforcedStyle should be rejected, but also all 'expanded' EnforcedStyle options as well, like for example EnforcedStyleForEmptyBraces. In order to achieve this I used a Regex when checking which keys should be rejected.


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.

@kpost kpost marked this pull request as draft November 14, 2023 10:52
@kpost kpost force-pushed the expand_enforced_style_options_in_auto_gen_enforced_style branch from 83e7056 to 9613eba Compare November 14, 2023 10:59
@kpost kpost marked this pull request as ready for review November 14, 2023 11:06
Copy link
Collaborator

@jonas054 jonas054 left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

Comment on lines 195 to 196
rejected_keys << /^EnforcedStyle\w*/ unless auto_gen_enforced_style?
cfg.reject { |key| include_or_match?(rejected_keys, key) }
Copy link
Member

Choose a reason for hiding this comment

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

Is there a logic by which the following would work, instead of creating the new include_or_match method?

Suggested change
rejected_keys << /^EnforcedStyle\w*/ unless auto_gen_enforced_style?
cfg.reject { |key| include_or_match?(rejected_keys, key) }
rejected_keys << 'EnforcedStyle' unless auto_gen_enforced_style?
cfg.reject do |key|
rejected_keys.any? { |rejected_key| key.start_with?(rejected_key) }
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this would work too! However then it only works for prefixed strings of course. I tried to anticipate for possible use cases where a key would not necessarily just start with the rejected key.

Copy link
Member

Choose a reason for hiding this comment

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

Even if the current logic is left as is, /^EnforcedStyle\w*/ appears like it should be /\AEnforcedStyle\w*/.

Copy link
Contributor Author

@kpost kpost Nov 30, 2023

Choose a reason for hiding this comment

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

Yes, but any regexp could be used. :)

Edit: Ah, sorry, understood you wrong. You're right, \A should be added! What is your opinion on using regexes?

@bbatsov bbatsov merged commit c51dfec into rubocop:master Jan 12, 2024
19 checks passed
@bbatsov
Copy link
Collaborator

bbatsov commented Jan 12, 2024

I'm fine with the proposed change. 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.

None yet

4 participants