Skip to content

Commit

Permalink
Fix duplicate extension cop versions when rubocop -V
Browse files Browse the repository at this point in the history
Follow #9349 (comment).

This PR fixes duplicate extension cop versions when `rubocop -V`.

The following is an example:

```yaml
# ext.yml
require:
  - rubocop-rspec

# .rubocop.yml
inherit_from: ext.yml
require:
  - rubocop-performance
  - rubocop-rspec

## Before

If there are duplicate requires, extension cop display will also be duplicated.
Duplicate requires will be displayed in duplicate.

```console
% rubocop -V
1.8.0 (using Parser 3.0.0.0, rubocop-ast 1.4.0, running on ruby 2.7.2 x86_64-darwin19)
  - rubocop-performance 1.9.2
  - rubocop-rspec 2.0.0
  - rubocop-rspec 2.0.0
```

## After

Even if there are duplicate requires, they will only be displayed once per extension cop.

```console
% rubocop -V
1.8.0 (using Parser 3.0.0.0, rubocop-ast 1.4.0, running on ruby 2.7.2 x86_64-darwin19)
  - rubocop-performance 1.9.2
  - rubocop-rspec 2.0.0
```
  • Loading branch information
koic authored and bbatsov committed Jan 9, 2021
1 parent b096982 commit 14858e4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
@@ -0,0 +1 @@
* [#9356](https://github.com/rubocop-hq/rubocop/pull/9356): Fix duplicate extension cop versions when using `rubocop -V`. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/config_loader.rb
Expand Up @@ -175,7 +175,7 @@ def merge_with_default(config, config_file, unset_nil: true)
end

def loaded_features
@loaded_features.flatten.compact
@loaded_features.flatten.compact.uniq
end

# @api private
Expand Down
25 changes: 25 additions & 0 deletions spec/rubocop/cli/cli_options_spec.rb
Expand Up @@ -177,6 +177,31 @@
end
end

context 'when requiring redundant extension cop' do
before do
create_file('ext.yml', <<~YAML)
require:
- rubocop-rspec
YAML
create_file('.rubocop.yml', <<~YAML)
inherit_from: ext.yml
require:
- rubocop-performance
- rubocop-rspec
YAML
end

it 'shows with version of each extension cop once' do
output = `ruby -I . "#{rubocop}" -V --disable-pending-cops`
expect(output).to include(RuboCop::Version::STRING)
expect(output).to match(/Parser \d+\.\d+\.\d+/)
expect(output).to match(/rubocop-ast \d+\.\d+\.\d+/)
expect(output).to match(
/- rubocop-performance \d+\.\d+\.\d+\n - rubocop-rspec \d+\.\d+\.\d+\n\z/
)
end
end

context 'when there are pending cops' do
let(:pending_cop_warning) { <<~PENDING_COP_WARNING }
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
Expand Down

0 comments on commit 14858e4

Please sign in to comment.