diff --git a/changelog/fix_duplicate_ext_cop_versions_when_using_rubocop_verbose_version.md b/changelog/fix_duplicate_ext_cop_versions_when_using_rubocop_verbose_version.md new file mode 100644 index 000000000000..4a0526394c2f --- /dev/null +++ b/changelog/fix_duplicate_ext_cop_versions_when_using_rubocop_verbose_version.md @@ -0,0 +1 @@ +* [#9356](https://github.com/rubocop-hq/rubocop/pull/9356): Fix duplicate extension cop versions when using `rubocop -V`. ([@koic][]) diff --git a/lib/rubocop/config_loader.rb b/lib/rubocop/config_loader.rb index a0b66e06be8e..92d101275410 100644 --- a/lib/rubocop/config_loader.rb +++ b/lib/rubocop/config_loader.rb @@ -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 diff --git a/spec/rubocop/cli/cli_options_spec.rb b/spec/rubocop/cli/cli_options_spec.rb index 44a16a6cc085..1a07b87dc580 100644 --- a/spec/rubocop/cli/cli_options_spec.rb +++ b/spec/rubocop/cli/cli_options_spec.rb @@ -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.