Skip to content

Commit

Permalink
Merge pull request #10875 from ydah/fix/duplicate_parameter
Browse files Browse the repository at this point in the history
Fix an obsolete option configuration values are duplicated when generating `.rubocop_todo.yml`
  • Loading branch information
koic committed Aug 6, 2022
2 parents abd1347 + 79c6b95 commit 265a9e6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_fix_an_obsolete_option_configuration.md
@@ -0,0 +1 @@
* [#10875](https://github.com/rubocop/rubocop/pull/10875): Fix an obsolete option configuration values are duplicated when generating `.rubocop_todo.yml`. ([@ydah][])
2 changes: 1 addition & 1 deletion lib/rubocop/formatter/disabled_config_formatter.rb
Expand Up @@ -161,7 +161,7 @@ def output_cop_param_comments(output_buffer, params, default_cfg)
next unless value.is_a?(Array)
next if value.empty?

output_buffer.puts "# #{param}: #{value.join(', ')}"
output_buffer.puts "# #{param}: #{value.uniq.join(', ')}"
end
end

Expand Down
27 changes: 27 additions & 0 deletions spec/rubocop/cli/auto_gen_config_spec.rb
Expand Up @@ -951,6 +951,33 @@ def a; end
YAML
end

context 'when configurable parameter is an obsolete parameter' do
it 'displayed as a new parameter setting value without duplication' do
create_file('.rubocop.yml', <<~YAML)
AllCops:
NewCops: enable
Naming/MethodName:
# `IgnoredPatterns` is obsolete. `AllowedPatterns` is newly used.
IgnoredPatterns:
- change
- not_change
YAML
create_file('example1.rb', ['# frozen_string_literal: true', '', 'def fooBar; end'])
create_file('example2.rb', ['# frozen_string_literal: true', '', 'def fooBar; end'])

expect(cli.run(['--auto-gen-config'])).to eq(0)
File.readlines('.rubocop_todo.yml')
expect(File.readlines('.rubocop_todo.yml')[9..].join)
.to eq(<<~YAML)
# Configuration parameters: AllowedPatterns, IgnoredPatterns.
# SupportedStyles: snake_case, camelCase
# AllowedPatterns: change, not_change
Naming/MethodName:
EnforcedStyle: camelCase
YAML
end
end

it 'does not generate configuration for the Syntax cop' do
create_file('example1.rb', <<~RUBY)
# frozen_string_literal: true
Expand Down

0 comments on commit 265a9e6

Please sign in to comment.