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

Fix an obsolete option configuration values are duplicated when generating .rubocop_todo.yml #10875

Merged
merged 1 commit into from Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:
ydah marked this conversation as resolved.
Show resolved Hide resolved
- 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