-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Warn duplicated keys in .rubocop.yml #6733
Conversation
@@ -3928,7 +3928,7 @@ Style/SafeNavigation: | |||
safe navigation (`&.`). | |||
Enabled: true | |||
VersionAdded: '0.43' | |||
VersionChanged: '0.44' | |||
VersionChanged: '0.56' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are duplicated since VersionChanged
was added.
https://github.com/rubocop-hq/rubocop/blob/b0e724d3f23a1489ed83cea52fd02830165f88b9/config/default.yml#L3873-L3890
v0.56.0 has a changelog entry for this cop, so I choose 0.56
.
https://github.com/rubocop-hq/rubocop/blob/dfbb6fd1d7d25342f942dfe43bd4f1d6a603d9bf/CHANGELOG.md#changes-11
Great idea! 👍🏻 |
Dir.chdir(dir, &block) | ||
ensure | ||
reset_pwd | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test cases ware failed by caching Dir.pwd
unfortunately.
So I added RuboCop::PathUtil.chdir
, and use it instead of Dir.chdir
to clear invalid cache.
rubocop.gemspec
Outdated
@@ -9,7 +9,7 @@ Gem::Specification.new do |s| | |||
s.name = 'rubocop' | |||
s.version = RuboCop::Version::STRING | |||
s.platform = Gem::Platform::RUBY | |||
s.required_ruby_version = '>= 2.2.0' | |||
s.required_ruby_version = '>= 2.2.2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Psych v3.1 supports Ruby 2.2.2 or higher.
https://github.com/ruby/psych/blob/v3.1.0/psych.gemspec#L50
So we need to drop supporting of Ruby 2.2.1 and 2.2.0.
I think it is not a big problem. RuboCop still supports Ruby 2.2.x. And I think we'll drop Ruby 2.2 soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but I worried about the following.
Dropping the Ruby version 2.2.1 and 2.2.0 may be better opened as a separate PR. And you can also edit the code using Psych at that time.
https://github.com/rubocop-hq/rubocop/pull/6733/files#diff-e2fc41e8fa0504d203570a8d822495afL186
I think that the opportunity for users to know written in CHANGELOG will increase than to investigate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comment. I'll create a pull request to drop Ruby 2.2.1 and 2.2.0. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a pull request. #6766
Thank you!
rubocop.gemspec
Outdated
@@ -38,6 +38,7 @@ Gem::Specification.new do |s| | |||
s.add_runtime_dependency('parallel', '~> 1.10') | |||
s.add_runtime_dependency('parser', '>= 2.5', '!= 2.5.1.1') | |||
s.add_runtime_dependency('powerpack', '~> 0.1') | |||
s.add_runtime_dependency('psych', '>= 3.1.0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change needs Psych v3.0.0 or higher to use start_line
method.
But I choose to use v3.1.0
or higher because we can simplify calling Psych.load
method argument by using filename
keyword argument since v3.1.0.
https://github.com/rubocop-hq/rubocop/pull/6733/files#diff-e2fc41e8fa0504d203570a8d822495afL187
So I think v3.1.0 is better.
raise "#{fname} has duplication of #{key1.value} " \ | ||
"on line #{key1.start_line} and line #{key2.start_line}" | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case checks the default config file does not have any duplication.
It's ready to review now. Thanks! |
CHANGELOG.md
Outdated
@@ -27,6 +27,7 @@ | |||
* [#6725](https://github.com/rubocop-hq/rubocop/issues/6725): Mark `Style/SymbolProc` as unsafe for auto-correct. ([@drenmi][]) | |||
* [#6708](https://github.com/rubocop-hq/rubocop/issues/6708): Make `Style/CommentedKeyword` allow the `:yields:` RDoc comment. ([@bquorning][]) | |||
* [#6749](https://github.com/rubocop-hq/rubocop/pull/6749): Make some cops aware of safe navigation operator. ([@hoshinotsuyoshi][]) | |||
* [#6733](https://github.com/rubocop-hq/rubocop/pull/6733): Warn duplicated keys in `.rubocop.yml`. ([@pocke][]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RuboCop 0.64.0 has been released and I merged #6766. Can you move this entry to ## master (unreleased)
and rebase with the latest master?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the entry of CHANGELOG and rebased, Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not seem to be updated. Did you forget force push?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's right, sorry for my mistake. I pushed it to rubocop-hq/rubocop repo unexpectedly.
I've fixed!
Thanks! |
Problem
Sometimes
.rubocop.yml
has duplicated keys, but RuboCop ignores them. It confuses us.For example #6728
Solution
Warn duplicated keys in .rubocop.yml.
For example
$ rubocop .rubocop.yml:2: `Metrics/BlockLength` is concealed by line 7 Inspecting 0 files 0 files inspected, no offenses detected
TODOs
PathUtil.pwd
, so they are failed.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.