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

Skip LineLength phase on --auto-gen-only-exclude #12730

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12730](https://github.com/rubocop/rubocop/pull/12730): Skip `LineLength` phase on `--auto-gen-only-exclude`. ([@sambostock][])
15 changes: 12 additions & 3 deletions lib/rubocop/cli/command/auto_generate_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class AutoGenerateConfig < Base

PHASE_1_OVERRIDDEN = '(skipped because the default Layout/LineLength:Max is overridden)'
PHASE_1_DISABLED = '(skipped because Layout/LineLength is disabled)'
PHASE_1_SKIPPED = '(skipped because a list of cops is passed to the `--only` flag)'
PHASE_1_SKIPPED_ONLY_COPS =
'(skipped because a list of cops is passed to the `--only` flag)'
PHASE_1_SKIPPED_ONLY_EXCLUDE =
'(skipped because only excludes will be generated due to `--auto-gen-only-exclude` flag)'

def run
add_formatter
Expand All @@ -29,12 +32,14 @@ def run
private

def maybe_run_line_length_cop
if !line_length_enabled?(@config_store.for_pwd)
if only_exclude?
skip_line_length_cop(PHASE_1_SKIPPED_ONLY_EXCLUDE)
elsif !line_length_enabled?(@config_store.for_pwd)
skip_line_length_cop(PHASE_1_DISABLED)
elsif !same_max_line_length?(@config_store.for_pwd, ConfigLoader.default_configuration)
skip_line_length_cop(PHASE_1_OVERRIDDEN)
elsif options_has_only_flag?
skip_line_length_cop(PHASE_1_SKIPPED)
skip_line_length_cop(PHASE_1_SKIPPED_ONLY_COPS)
else
run_line_length_cop
end
Expand Down Expand Up @@ -65,6 +70,10 @@ def options_has_only_flag?
@options[:only]
end

def only_exclude?
@options[:auto_gen_only_exclude]
end

# Do an initial run with only Layout/LineLength so that cops that
# depend on Layout/LineLength:Max get the correct value for that
# parameter.
Expand Down
11 changes: 8 additions & 3 deletions spec/rubocop/cli/auto_gen_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1309,8 +1309,13 @@ def function(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
# absolute Exclude paths will point into this example's work directory.
RuboCop::ConfigLoader.default_configuration = nil

$stdout = StringIO.new
expect(cli.run(['--auto-gen-config', '--auto-gen-only-exclude',
'--exclude-limit', '1'])).to eq(0)
expect($stdout.string.include?(<<~STRING)).to be(true)
Phase 1 of 2: run Layout/LineLength cop (skipped because only excludes will be generated due to `--auto-gen-only-exclude` flag)
Phase 2 of 2: run all cops
STRING
actual = File.read('.rubocop_todo.yml').split($RS)

# With --exclude-limit 1 we get MinDigits generated for NumericLiterals
Expand All @@ -1319,6 +1324,9 @@ def function(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
# the same cop in a single file. Exclude properties are generated for
# them.
expect(actual.grep(/^[^#]/).join($RS)).to eq(<<~YAML.chomp)
Layout/LineLength:
Exclude:
- 'example1.rb'
Lint/UnusedMethodArgument:
Exclude:
- 'example2.rb'
Expand All @@ -1329,9 +1337,6 @@ def function(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
Enabled: false
Style/NumericLiterals:
MinDigits: 7
Layout/LineLength:
Exclude:
- 'example1.rb'
YAML
end

Expand Down