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

Warn duplicated keys in .rubocop.yml #6733

Merged
merged 1 commit into from
Feb 15, 2019
Merged

Warn duplicated keys in .rubocop.yml #6733

merged 1 commit into from
Feb 15, 2019

Conversation

pocke
Copy link
Collaborator

@pocke pocke commented Feb 5, 2019

Problem

Sometimes .rubocop.yml has duplicated keys, but RuboCop ignores them. It confuses us.
For example #6728

# RuboCop ignores this configuration.
Metrics/BlockLength:
  Max: 50

# long long lines

Metrics/BlockLength:
  Max: 25

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

  • Write test for YAMLDuplicationChecker
  • Fix existing tests that are failed
    • RuboCop uses wrong cache of PathUtil.pwd, so they are failed.

Before submitting the PR make sure the following are checked:

  • 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.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@@ -3928,7 +3928,7 @@ Style/SafeNavigation:
safe navigation (`&.`).
Enabled: true
VersionAdded: '0.43'
VersionChanged: '0.44'
VersionChanged: '0.56'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Drenmi
Copy link
Collaborator

Drenmi commented Feb 6, 2019

Great idea! 👍🏻

Dir.chdir(dir, &block)
ensure
reset_pwd
end
Copy link
Collaborator Author

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'
Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator Author

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. 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

🎉

Copy link
Collaborator Author

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')
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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.

@pocke pocke changed the title [WIP] Warn duplicated keys in .rubocop.yml Warn duplicated keys in .rubocop.yml Feb 7, 2019
@pocke
Copy link
Collaborator Author

pocke commented Feb 7, 2019

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][])
Copy link
Member

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?

Copy link
Collaborator Author

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!

Copy link
Member

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?

Copy link
Collaborator Author

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!

@koic
Copy link
Member

koic commented Feb 15, 2019

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

3 participants