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

Layout/HashAlignment Autocorrect crashes for calls with arguments on next line after shorthand hash argument #10364

Closed
ErikSchierboom opened this issue Jan 19, 2022 · 5 comments · Fixed by #10393
Labels

Comments

@ErikSchierboom
Copy link

Expected behavior

Successfully autocorrect code with arguments following a hash shorthand argument that are on different lines.

Actual behavior

If I try to autocorrect a file that use a Ruby 3.1 hash shorthand with one or more hash parameters following it one the next line, an inifinite loop error is raised.

bundle exec rubocop --debug --auto-correct app/helpers/view_components/track/solution_activity.rb
For /Users/erik/Code/exercism/website: configuration from /Users/erik/Code/exercism/website/.rubocop.yml
configuration from /Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-rails-2.13.1/config/default.yml
configuration from /Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-rails-2.13.1/config/default.yml
Default configuration from /Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/config/default.yml
configuration from /Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-minitest-0.17.0/config/default.yml
configuration from /Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-minitest-0.17.0/config/default.yml
configuration from /Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-performance-1.13.1/config/default.yml
configuration from /Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-performance-1.13.1/config/default.yml
Inspecting 1 file
Scanning /Users/erik/Code/exercism/website/app/helpers/view_components/track/solution_activity.rb
C

Offenses:

app/helpers/view_components/track/solution_activity.rb:3:3: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
  hash_param_with_value: false
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/helpers/view_components/track/solution_activity.rb:3:18: C: [Corrected] Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.
                 hash_param_with_value: false
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in /Users/erik/Code/exercism/website/app/helpers/view_components/track/solution_activity.rb and caused by Layout/HashAlignment -> Layout/ArgumentAlignment
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:298:in `check_for_infinite_loop'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:281:in `block in iterate_until_no_changes'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:280:in `loop'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:280:in `iterate_until_no_changes'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:249:in `do_inspection_loop'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:130:in `block in file_offenses'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:155:in `file_offense_cache'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:129:in `file_offenses'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:120:in `process_file'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:100:in `each'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:100:in `reduce'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:86:in `inspect_files'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/runner.rb:47:in `run'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/cli.rb:71:in `run_command'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/cli.rb:78:in `execute_runners'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/lib/rubocop/cli.rb:47:in `run'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/exe/rubocop:12:in `block in <top (required)>'
/Users/erik/.rvm/rubies/ruby-3.1.0/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/Users/erik/.rvm/gems/ruby-3.1.0/gems/rubocop-1.25.0/exe/rubocop:12:in `<top (required)>'
/Users/erik/.rvm/gems/ruby-3.1.0/bin/rubocop:25:in `load'
/Users/erik/.rvm/gems/ruby-3.1.0/bin/rubocop:25:in `<main>'
/Users/erik/.rvm/gems/ruby-3.1.0/bin/ruby_executable_hooks:22:in `eval'
/Users/erik/.rvm/gems/ruby-3.1.0/bin/ruby_executable_hooks:22:in `<main>'
Finished in 0.6285099999995509 seconds

Steps to reproduce the problem

The following code causes the above failure:

fails(
  regular_param, hash_param:,
  hash_param_with_value:
)

Changing the argument on the second line to not be a shorthand value still has the same error:

fails(
  regular_param, hash_param:,
  hash_param_with_value: false
)

Changing the code to a one-liner causes the error to disappear:

succeeds(
  regular_param, hash_param:, hash_param_with_value: false
)

Changing the shorthand to a non-shorthand param also causes the error to disappear:

succeeds(
  regular_param, hash_param: 1, hash_param_with_value: false
)

RuboCop version

$ bundle exec rubocop -V
1.25.0 (using Parser 3.1.0.0, rubocop-ast 1.15.1, running on ruby 3.1.0 x86_64-darwin20)
  - rubocop-minitest 0.17.0
  - rubocop-performance 1.13.1
  - rubocop-rails 2.13.1
@koic
Copy link
Member

koic commented Jan 19, 2022

Thank you for the feedback. I cannot reproduce the error. Can you provide .rubocop.yml configuration?

@ErikSchierboom
Copy link
Author

ErikSchierboom commented Jan 19, 2022

Sure

require:
  - rubocop-rails
  - rubocop-minitest
  - rubocop-performance

AllCops:
  NewCops: disable
  Exclude:
    - "app/controllers/tmp/**/*"
    - "bin/**/*"
    - "bin/{bundle,monitor-manifest,rails,rake,setup,yarn}"
    - "db/schema.rb"
    - "db/migrate/*"
    - "db/seeds.rb"
    - "node_modules/**/*"
    - "lib/solargraph-rails.rb"
    - "scripts/**/*"

Bundler/OrderedGems:
  Enabled: false

Layout/ArgumentAlignment:
  EnforcedStyle: with_fixed_indentation

Layout/DotPosition:
  EnforcedStyle: trailing

Layout/EndOfLine:
  EnforcedStyle: lf

Layout/MultilineMethodCallIndentation:
  EnforcedStyle: indented

Layout/EmptyLinesAroundAccessModifier:
  EnforcedStyle: only_before

Layout/LineLength:
  Max: 135
  AutoCorrect: true
  Exclude:
    - "config/**/*"
    - "test/models/notifications/*"
    - "test/helpers/react_components/maintaining/submissions_summary_table_test.rb"

Layout/RescueEnsureAlignment:
  Exclude:
    - app/controllers/api/solutions_controller.rb # TODO: remove once Rubocop fixes https://github.com/rubocop/rubocop/pull/10017

Lint/SuppressedException:
  Exclude:
    - "test/**/*"

Metrics/BlockLength:
  Exclude:
    - "test/**/*"

Metrics/MethodLength:
  # We probably want to bring this down but let's start here for now
  Max: 20
  Exclude:
    - "test/**/*"

Metrics/AbcSize:
  IgnoredMethods: ["CLI::PrepareUploadedFiles.call"]

Naming/PredicateName:
  Enabled: false

Style/ConditionalAssignment:
  EnforcedStyle: assign_inside_condition
  SingleLineConditionsOnly: false
  IncludeTernaryExpressions: false

Style/StringLiterals:
  Enabled: false

Style/FrozenStringLiteralComment:
  Enabled: false

Style/Documentation:
  Enabled: false

Style/DocumentationMethod:
  Enabled: false

Style/DoubleNegation:
  Enabled: false

Style/RedundantSelf:
  Enabled: false

Style/MultilineTernaryOperator:
  Enabled: false

Style/ZeroLengthPredicate:
  Enabled: false

# I don't mind this being enabled if
# someone fixes all the fails.
Style/ClassAndModuleChildren:
  Enabled: false

Naming/VariableNumber:
  EnforcedStyle: snake_case
  AllowedIdentifiers:
    - "strip_h1"
    - "v2"

Style/LambdaCall:
  EnforcedStyle: braces

Rails/HasManyOrHasOneDependent:
  Exclude:
    - "app/models/exercise/representation.rb"
    - "app/models/submission/representation.rb"

Rails/FilePath:
  EnforcedStyle: arguments

Rails/LexicallyScopedActionFilter:
  Enabled: false

Rails/RefuteMethods:
  EnforcedStyle: refute

Rails/OutputSafety:
  Enabled: false

Rails/SkipsModelValidations:
  Enabled: false

Rails/HelperInstanceVariable:
  Exclude:
    - "app/helpers/view_components/**/*"
    - "app/helpers/react_components/**/*"

@koic
Copy link
Member

koic commented Jan 20, 2022

The error can be reproduced. Thank you for providing the configuration.

@koic koic added the bug label Jan 20, 2022
@ErikSchierboom
Copy link
Author

Perfect! Good luck fixing the issue.

koic added a commit to koic/rubocop that referenced this issue Feb 1, 2022
Fixes rubocop#10364.

This PR fixes an infinite loop error for `Layout/HashAlignment` when
`EnforcedStyle: with_fixed_indentation` is specified for `Layout/ArgumentAlignment`.
The issue context is that the first keyword argument and the argument before it
are on the same line.
bbatsov pushed a commit that referenced this issue Feb 3, 2022
Fixes #10364.

This PR fixes an infinite loop error for `Layout/HashAlignment` when
`EnforcedStyle: with_fixed_indentation` is specified for `Layout/ArgumentAlignment`.
The issue context is that the first keyword argument and the argument before it
are on the same line.
@ErikSchierboom
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants