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

Unification of IgnoredMethods #9098

Merged
merged 2 commits into from Nov 26, 2020

Conversation

dvandersluis
Copy link
Member

@dvandersluis dvandersluis commented Nov 25, 2020

As mentioned by @bbatsov at #9058 (comment)

  1. The two cops that were configured using ExcludedMethods instead of IgnoredMethods (Metrics/BlockLength and Metrics/MethodLength) have been changed to use IgnoredMethods going forward. I changed the IgnoredMethods mixin so that it can be configured to allow for those two cops to continue accepting ExcludedMethods without adding that config key to the reset of the cops.
  2. All cops that use the IgnoredMethods mixin now can accept an array of both strings and regexes, and both are applied.

Questions:

  • Is there a good way to document this so that users will know they can use regexes for IgnoredMethods everywhere now? I added a new section to configuration.adoc.
  • Is there a way to add a deprecation warning when running rubocop with ExcludedMethods in the configuration so that users can update their config?

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.

Comment on lines +52 to 63
def method_receiver_excluded?(node)
node_receiver = node.receiver&.source&.gsub(/\s+/, '')
node_method = String(node.method_name)

excluded_methods.any? do |config|
ignored_methods.any? do |config|
next unless config.is_a?(String)

receiver, method = config.split('.')
Copy link
Member Author

Choose a reason for hiding this comment

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

Metrics/BlockLength has a special case for IgnoredMethods, where it allows for values to be fully qualified methods, and it uses this to test receivers. I kept this logic of course, but this is now an exception from how all the other IgnoredMethods cops work.

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 25, 2020

Is there a good way to document this so that users will know they can use regexes for IgnoredMethods everywhere now?

Can't think of anything other than something in the "Configuration" part of the docs.

Is there a way to add a deprecation warning when running rubocop with ExcludedMethods in the configuration so that users can update their config?

Yes - look for ConfigObsoletion.

@dvandersluis
Copy link
Member Author

dvandersluis commented Nov 25, 2020

Yes - look for ConfigObsoletion.

Looks like OBSOLETE_PARAMETERS from ConfigObsoletion gives an error instead of allowing it, which makes my configuration to still be able to use ExcludedMethods not very useful since rubocop won't run anyways. What do you suggest @bbatsov?

$ rubocop
Error: obsolete parameter ExcludedMethods (for Metrics/BlockLength) found in .rubocop.yml
`ExcludedMethods` has been renamed to `IgnoredMethods`.
obsolete parameter ExcludedMethods (for Metrics/MethodLength) found in .rubocop.yml
`ExcludedMethods` has been renamed to `IgnoredMethods`.

@dvandersluis
Copy link
Member Author

spec/rubocop/config_loader_spec.rb:740 is failing in CI but not via bundle exec rake default. Anyone have any ideas?

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 25, 2020

I'm assuming some dep got updated on the CI.

which makes my configuration to still be able to use ExcludedMethods not very useful since rubocop won't run anyways. What do you suggest @bbatsov?

Damn, I had forgotten that in the past we already raised error. I guess we should make the code there a bit more flexible and make it show errors or warnings.

@dvandersluis
Copy link
Member Author

Damn, I had forgotten that in the past we already raised error. I guess we should make the code there a bit more flexible and make it show errors or warnings.

I'll take a look at it!

@dvandersluis
Copy link
Member Author

@bbatsov I think everything has been taken care of now. I've added to the documentation and the deprecation message is now set up.

@dvandersluis
Copy link
Member Author

One other thing -- I needed to keep ExcludedMethods in config/default.yml or rubocop will complain about unsupported parameters. However, this will add it to the doc for the cop. I added a note for both cops to explain why there's both, hopefully that will be sufficient.

…edMethods` instead of `ExcludedMethods` in configuration. The previous key is retained for backwards compatibility.
…th strings and regexes in the configuration.
@bbatsov bbatsov merged commit c67ecc7 into rubocop:master Nov 26, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Nov 26, 2020

Fantastic work! 🙇‍♂️

@dvandersluis dvandersluis deleted the excluded-ignored-methods branch January 18, 2021 20:42
skalee added a commit to skalee/guides that referenced this pull request Apr 8, 2021
Rename ExcludedMethods to IgnoredMethods cop parameter,
as it has been changed in Rubocop 1.5.0.

Note: The old parameter name is still supported, though deprecated.

See: rubocop/rubocop#9098
skalee added a commit to skalee/guides that referenced this pull request Apr 8, 2021
Rename ExcludedMethods cop parameter to IgnoredMethods,
as it has been changed in Rubocop 1.5.0.

Note: The old parameter name is still supported, though deprecated.

See: rubocop/rubocop#9098
nickcharlton pushed a commit to thoughtbot/guides that referenced this pull request Apr 16, 2021
Rename ExcludedMethods cop parameter to IgnoredMethods,
as it has been changed in Rubocop 1.5.0.

Note: The old parameter name is still supported, though deprecated.

See: rubocop/rubocop#9098
agatheblues added a commit to bitcrowd/rubocop-bitcrowd that referenced this pull request Sep 9, 2021
agatheblues added a commit to bitcrowd/rubocop-bitcrowd that referenced this pull request Sep 10, 2021
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

2 participants