-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix incorrect behavior when Layout/LineLength is disabled
#14658
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
Merged
bbatsov
merged 1 commit into
rubocop:master
from
koic:fix_incorrect_behavior_when_layout_line_length_is_disabled
Nov 14, 2025
Merged
Fix incorrect behavior when Layout/LineLength is disabled
#14658
bbatsov
merged 1 commit into
rubocop:master
from
koic:fix_incorrect_behavior_when_layout_line_length_is_disabled
Nov 14, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This change corrects some cops that previously assumed `Layout/LineLength` was always enabled. They now respect the cop's actual enablement state, matching the expected behavior in the updated tests. The update removes hard-coded `max_line_length` lookups, delegates to shared logic, and ensures consistent behavior across cops.
Collaborator
|
Great change, that we should have done much earlier. Thanks! |
viralpraxis
added a commit
to viralpraxis/rubocop
that referenced
this pull request
Dec 19, 2025
Follow-up to rubocop#14658 If `Layout/LineLength` is disabled but forced (via `--only`), it throws the same error as in rubocop#14719. Looks like the easies way to fix that is to override `LineLength#max_line_length` method. The error without the patch: ```shell Failures: 1) RuboCop::CLI options --only when one cop is given when specifying disabled `Layout/LineLength` cop enables the given cop Got 2 failures from failure aggregation block. # ./spec/support/cli_spec_behavior.rb:26:in 'block (2 levels) in <top (required)>' # ./lib/rubocop/rspec/shared_contexts.rb:44:in 'block (2 levels) in <top (required)>' # ./lib/rubocop/rspec/shared_contexts.rb:29:in 'block (4 levels) in <top (required)>' # ./lib/rubocop/rspec/shared_contexts.rb:29:in 'Dir.chdir' # ./lib/rubocop/rspec/shared_contexts.rb:29:in 'block (3 levels) in <top (required)>' # ./lib/rubocop/rspec/shared_contexts.rb:7:in 'block (2 levels) in <top (required)>' 1.1) Failure/Error: expect(cli.run(['--format', 'simple', '--only', 'Layout/LineLength', 'example.rb'])).to be_zero expected `1.zero?` to be truthy, got false # ./spec/rubocop/cli/options_spec.rb:735:in 'block (5 levels) in <top (required)>' 1.2) Failure/Error: expect($stderr.string).to eq('') expected: "" got: "An error occurred while Layout/LineLength cop was inspecting /tmp/d20251219-51392-5a0566/work/exampl...Parser 3.3.10.0, rubocop-ast 1.48.0, analyzing as Ruby 2.7, running on ruby 3.4.7) [x86_64-linux]\n" (compared using ==) Diff: @@ -0,0 +1,11 @@ +An error occurred while Layout/LineLength cop was inspecting /tmp/d20251219-51392-5a0566/work/example.rb. +To see the complete backtrace run rubocop -d. + +1 error occurred: +An error occurred while Layout/LineLength cop was inspecting /tmp/d20251219-51392-5a0566/work/example.rb. +Errors are usually caused by RuboCop bugs. +Please, update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version. +https://github.com/rubocop/rubocop/issues + +Mention the following information in the issue report: +1.82.0 (using Parser 3.3.10.0, rubocop-ast 1.48.0, analyzing as Ruby 2.7, running on ruby 3.4.7) [x86_64-linux] # ./spec/rubocop/cli/options_spec.rb:736:in 'block (5 levels) in <top (required)>' Finished in 0.10147 seconds (files took 0.77374 seconds to load) 1 example, 1 failure Failed examples: rspec ./spec/rubocop/cli/options_spec.rb:723 # RuboCop::CLI options --only when one cop is given when specifying disabled `Layout/LineLength` cop enables the given cop Randomized with seed 44805 ```
8 tasks
viralpraxis
added a commit
to viralpraxis/rubocop
that referenced
this pull request
Dec 21, 2025
Follow-up to rubocop#14658 If `Layout/LineLength` is disabled but forced (via `--only`), it throws the same error as in rubocop#14719. Looks like the easies way to fix that is to override `LineLength#max_line_length` method. The error without the patch: ```shell Failures: 1) RuboCop::CLI options --only when one cop is given when specifying disabled `Layout/LineLength` cop enables the given cop Got 2 failures from failure aggregation block. # ./spec/support/cli_spec_behavior.rb:26:in 'block (2 levels) in <top (required)>' # ./lib/rubocop/rspec/shared_contexts.rb:44:in 'block (2 levels) in <top (required)>' # ./lib/rubocop/rspec/shared_contexts.rb:29:in 'block (4 levels) in <top (required)>' # ./lib/rubocop/rspec/shared_contexts.rb:29:in 'Dir.chdir' # ./lib/rubocop/rspec/shared_contexts.rb:29:in 'block (3 levels) in <top (required)>' # ./lib/rubocop/rspec/shared_contexts.rb:7:in 'block (2 levels) in <top (required)>' 1.1) Failure/Error: expect(cli.run(['--format', 'simple', '--only', 'Layout/LineLength', 'example.rb'])).to be_zero expected `1.zero?` to be truthy, got false # ./spec/rubocop/cli/options_spec.rb:735:in 'block (5 levels) in <top (required)>' 1.2) Failure/Error: expect($stderr.string).to eq('') expected: "" got: "An error occurred while Layout/LineLength cop was inspecting /tmp/d20251219-51392-5a0566/work/exampl...Parser 3.3.10.0, rubocop-ast 1.48.0, analyzing as Ruby 2.7, running on ruby 3.4.7) [x86_64-linux]\n" (compared using ==) Diff: @@ -0,0 +1,11 @@ +An error occurred while Layout/LineLength cop was inspecting /tmp/d20251219-51392-5a0566/work/example.rb. +To see the complete backtrace run rubocop -d. + +1 error occurred: +An error occurred while Layout/LineLength cop was inspecting /tmp/d20251219-51392-5a0566/work/example.rb. +Errors are usually caused by RuboCop bugs. +Please, update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version. +https://github.com/rubocop/rubocop/issues + +Mention the following information in the issue report: +1.82.0 (using Parser 3.3.10.0, rubocop-ast 1.48.0, analyzing as Ruby 2.7, running on ruby 3.4.7) [x86_64-linux] # ./spec/rubocop/cli/options_spec.rb:736:in 'block (5 levels) in <top (required)>' Finished in 0.10147 seconds (files took 0.77374 seconds to load) 1 example, 1 failure Failed examples: rspec ./spec/rubocop/cli/options_spec.rb:723 # RuboCop::CLI options --only when one cop is given when specifying disabled `Layout/LineLength` cop enables the given cop Randomized with seed 44805 ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change corrects some cops that previously assumed
Layout/LineLengthwas always enabled.They now respect the cop's actual enablement state, matching the expected behavior in the updated tests.
The update removes hard-coded
max_line_lengthlookups, delegates to shared logic, and ensures consistent behavior across cops.Before submitting the PR make sure the following are checked:
[Fix #issue-number](if the related issue exists).master(if not - rebase it).bundle exec rake default. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.mdif the new code introduces user-observable changes. See changelog entry format for details.