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

Add InternalAffairs/UndefinedConfig cop. #9987

Merged
merged 2 commits into from Aug 10, 2021

Conversation

dvandersluis
Copy link
Member

Adds an internal affairs cop to look for cops that use a configuration key without it being defined in config/default.yml.

I ran into this while adding a cop and accidentally putting a configuration in the wrong element. This internal affairs cop ensures that any configuration key used with cop_config in a cop is present in the configuration for that cop.


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.

@@ -1824,7 +1824,6 @@ Lint/MultipleComparison:
Enabled: true
VersionAdded: '0.47'
VersionChanged: '1.1'
AllowMethodComparison: true
Copy link
Member Author

Choose a reason for hiding this comment

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

@koic the cop caught this -- in #8953, this configuration appears to have been accidentally added to the configuration of Lint/MultipleComparison instead of Style/MultipleComparison!

@dvandersluis dvandersluis force-pushed the internal/undefined-config branch 3 times, most recently from aabe4d3 to f27588f Compare August 7, 2021 03:44
@koic
Copy link
Member

koic commented Aug 7, 2021

Great! This looks like a useful cop. The only thing I'm concern about is that rubocop-minitest may have a false positive.
https://github.com/rubocop/rubocop-minitest

diff --git a/Gemfile b/Gemfile
index ad573e7..6d83faa 100644
--- a/Gemfile
+++ b/Gemfile
@@ -8,6 +8,6 @@ gemspec

 gem 'bump', require: false
 gem 'rake'
-gem 'rubocop', github: 'rubocop/rubocop'
+gem 'rubocop', path: '/path/to/rubocop/rubocop'
 gem 'rubocop-performance', '~> 1.11.0'
 gem 'yard', '~> 0.9'
% bundle exec rake
(snip)

Offenses:

lib/rubocop/cop/minitest/multiple_assertions.rb:58:36: C: InternalAffairs/UndefinedConfig: Max is not defined in the configuration for Minitest/MultipleAssertions in config/default.yml.
          Integer(cop_config.fetch('Max', 3))
                                   ^^^^^

88 files inspected, 1 offense detected

rubocop-minitest can make a workaround to disable this cop if it's not easy to solve.

@dvandersluis
Copy link
Member Author

@koic should that cop not define Max: 3 in its configuration?

@koic
Copy link
Member

koic commented Aug 9, 2021

@dvandersluis
Copy link
Member Author

Oh strange, ok I'll look into it thanks!

@dvandersluis
Copy link
Member Author

@koic I haven't been able to replicate this, I ran the cop on rubocop-minitest and no offenses were raised...

@koic
Copy link
Member

koic commented Aug 10, 2021

@dvandersluis I checked again, but I couldn't reproduce the offense (maybe there was a problem with my local environment...?). Anyway, I'm sorry to take your time. And thank you again for implementing the useful cop!

@koic koic merged commit bb5d832 into rubocop:master Aug 10, 2021
@dvandersluis
Copy link
Member Author

Thanks @koic!

@dvandersluis dvandersluis deleted the internal/undefined-config branch September 14, 2021 16: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.

None yet

2 participants