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

Style/HashSyntax autocorrection adds redundant parens #11256

Closed
Niyokee opened this issue Dec 9, 2022 · 0 comments · Fixed by #11257
Closed

Style/HashSyntax autocorrection adds redundant parens #11256

Niyokee opened this issue Dec 9, 2022 · 0 comments · Fixed by #11257
Labels

Comments

@Niyokee
Copy link

Niyokee commented Dec 9, 2022

Expected behavior

Say, we have a code below

foo = 'foo'
bar = 'bar'

buzz foo: foo, bar: bar

def buzz(foo:, bar:); end

Autocorrection fixes the code like this

  • omitting keyword argument's values
  • adding parens
foo = 'foo'
bar = 'bar'

buzz(foo:, bar:)

def buzz(foo:, bar:); end

Actual behavior

Autocorrection adds the same number of parens as the number of keyword arguments of the method.

foo = 'foo'
bar = 'bar'

buzz(foo:, bar:))

def buzz(foo:, bar:); end

and, this is the debug log

bash-5.1#  rubocop -A --debug app/models/test.rb
For /app: configuration from /app/.rubocop.yml
configuration from /usr/local/bundle/gems/rubocop-performance-1.15.1/config/default.yml
configuration from /usr/local/bundle/gems/rubocop-performance-1.15.1/config/default.yml
Default configuration from /usr/local/bundle/gems/rubocop-1.40.0/config/default.yml
configuration from /usr/local/bundle/gems/rubocop-rails-2.17.3/config/default.yml
configuration from /usr/local/bundle/gems/rubocop-rails-2.17.3/config/default.yml
configuration from /usr/local/bundle/gems/rubocop-rspec-2.15.0/config/default.yml
configuration from /usr/local/bundle/gems/rubocop-rspec-2.15.0/config/default.yml
Inheriting configuration from /app/.rubocop_todo.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /app/app/models/test.rb
Loading cache from /root/.cache/rubocop_cache/0c5bb8b1e524101b67f11c14875a6c46c56250ba/cbff93e1a61a47763ca86fb62223c4e70a6840b1/22eea71e854462166381415295cdcfcc99be1b20
E

Offenses:

app/models/test.rb:6:11: C: [Corrected] Style/HashSyntax: Omit the hash value.
buzz foo: foo, bar: bar
          ^^^
app/models/test.rb:6:17: E: Lint/Syntax: unexpected token tRPAREN
(Using Ruby 3.1 parser; configure using TargetRubyVersion parameter, under AllCops)
buzz(foo:, bar:))
                ^
app/models/test.rb:6:21: C: [Corrected] Style/HashSyntax: Omit the hash value.
buzz foo: foo, bar: bar
                    ^^^

1 file inspected, 3 offenses detected, 2 offenses corrected
Finished in 0.9874286688864231 seconds

Steps to reproduce the problem

As the code above shows,

  1. Passing more than two keyword arguments to a method without omitting its values
  2. execute rubocop autocorrection

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler.
If you see extension cop versions (e.g. rubocop-performance, rubocop-rspec, and others)
output by rubocop -V, include them as well. Here's an example:

# bundle exec rubocop -V
1.40.0 (using Parser 3.1.3.0, rubocop-ast 1.24.0, running on ruby 3.1.3) [x86_64-linux-musl]
  - rubocop-performance 1.15.1
  - rubocop-rails 2.17.3
  - rubocop-rspec 2.15.0
@koic koic added the bug label Dec 9, 2022
koic added a commit to koic/rubocop that referenced this issue Dec 9, 2022
Fixes rubocop#11256.

This PR fixes an incorrect autocorrect for `Style/HashSyntax`
when without parentheses call expr follows after multiple keyword arguments method call.
koic added a commit that referenced this issue Dec 11, 2022
…style_hash_syntax

[Fix #11256] Fix an incorrect autocorrect for `Style/HashSyntax`
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