rubocop / rubocop-jp

A place for RuboCop discussions in Japanese
55 stars 2 forks source link

auto-correctすると要素が消える #45

Closed booink closed 6 years ago

booink commented 6 years ago

-v 0.60.0 で、auto-correct時に要素が消える現象が起きましたので、報告致します。

auto-correct前のソースコード

# frozen_string_literal: true

hoge = Hoge.new(
            { hoge: 'hoge',
              fuga: 'fuga',
              foo: 'this is dummy.'
            })

rubocop -a の出力

Inspecting 1 file
C

Offenses:

test.rb:4:3: C: [Corrected] Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
  { hoge: 'hoge', ...
  ^^^^^^^^^^^^^^^
test.rb:4:4: C: [Corrected] Layout/FirstParameterIndentation: Indent the first parameter one step more than the start of the previous line.
   hoge: 'hoge', ...
   ^^^^^^^^^^^^^
test.rb:4:13: C: [Corrected] Layout/FirstParameterIndentation: Indent the first parameter one step more than the start of the previous line.
            { hoge: 'hoge', ...
            ^^^^^^^^^^^^^^^
test.rb:4:13: C: [Corrected] Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
            { hoge: 'hoge', ...
            ^^^^^^^^^^^^^^^
test.rb:5:5: C: [Corrected] Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
    fuga: 'fuga',
    ^^^^^^^^^^^^
test.rb:5:17: C: [Corrected] Style/TrailingCommaInArguments: Avoid comma after the last parameter of a method call.
    fuga: 'fuga',
                ^
test.rb:6:1: C: [Corrected] Layout/ClosingParenthesisIndentation: Indent ) to column 1 (not 0)
)
^
test.rb:6:2: C: [Corrected] Layout/ClosingParenthesisIndentation: Indent ) to column 0 (not 1)
 )
 ^
test.rb:6:26: C: [Corrected] Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
    foo: 'this is dummy.'}
                         ^
test.rb:7:13: C: [Corrected] Layout/MultilineHashBraceLayout: Closing hash brace must be on the same line as the last hash element when opening brace is on the same line as the first hash element.
            })
            ^
test.rb:7:14: C: [Corrected] Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.
            })
             ^

1 file inspected, 11 offenses detected, 11 offenses corrected

auto-correct後のソースコード

# frozen_string_literal: true

hoge = Hoge.new(
  hoge: 'hoge',
  fuga: 'fuga'
)

Hoge.new時にキーワード引数ではなくHashで渡しているのがイレギュラーではあると思いますが...

koic commented 6 years ago

フィードバックありがとうございます。auto-correct で Hash 要素が消える問題に対する PR を以下に開きました。 rubocop-hq/rubocop/pull/6443