Skip to content

Commit

Permalink
Fix an obsolete option configuration values are duplicated when gener…
Browse files Browse the repository at this point in the history
…ating `.rubocop_todo.yml`

Create two files with the following code:
```ruby
def fooBar; end
```

Set the following in .rubocop.yml:
```yml
Style/MethodName:
  IgnoredPatterns:
    - pattern1
    - pattern2
```

Run `rubocop --auto-gen-config`
Then duplicate configuration values are enumerated in `.rubocop_todo.yml` as follows:
```yml
# Offense count: 2
# Configuration parameters: EnforcedStyle, AllowedPatterns, IgnoredPatterns.
# SupportedStyles: snake_case, camelCase
# AllowedPatterns: pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2, pattern1, pattern2
Naming/MethodName:
  Exclude:
    - 'test1.rb'
    - 'test2.rb'
```
  • Loading branch information
ydah committed Aug 6, 2022
1 parent 4f9cc54 commit 79c6b95
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 79c6b95

Please sign in to comment.