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

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

Closed
booink opened this issue Nov 1, 2018 · 1 comment · Fixed by rubocop/rubocop#6443
Closed

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

booink opened this issue Nov 1, 2018 · 1 comment · Fixed by rubocop/rubocop#6443

Comments

@booink
Copy link

booink commented Nov 1, 2018

-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 added a commit to koic/rubocop that referenced this issue Nov 5, 2018
Fixes rubocop/rubocop-jp#45. (This link is Japanese issue)

This PR fixes an incorrect autocorrect for `Style/BracesAroundHashParameters`
when the opening brace is before the first hash element.

```console
% rubocop -V
0.60.0 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-darwin17)

% cat example.rb
# frozen_string_literal: true

foo = Foo.new(
  { foo: 'foo',
    bar: 'bar',
    baz: 'this is the last element'}
)
```

The following difference is the execution result of `rubocop -a` command.

## Before

The last element is lost.

```diff
diff --git a/example.rb b/example.rb
index ecf9711..c9a02b8 100644
--- a/example.rb
+++ b/example.rb
@@ -1,7 +1,6 @@
 # frozen_string_literal: true

 foo = Foo.new(
-  { foo: 'foo',
-    bar: 'bar',
-    baz: 'this is the last element'}
+  foo: 'foo',
+  bar: 'bar'
 )
```

## After

Remove only the braces.

```diff
diff --git a/example.rb b/example.rb
index ecf9711..57790da 100644
--- a/example.rb
+++ b/example.rb
@@ -1,7 +1,7 @@
 # frozen_string_literal: true

 foo = Foo.new(
-  { foo: 'foo',
-    bar: 'bar',
-    baz: 'this is the last element'}
+  foo: 'foo',
+  bar: 'bar',
+  baz: 'this is the last element'
 )
```
@koic
Copy link
Member

koic commented Nov 5, 2018

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

bbatsov pushed a commit to rubocop/rubocop that referenced this issue Nov 5, 2018
Fixes rubocop/rubocop-jp#45. (This link is Japanese issue)

This PR fixes an incorrect autocorrect for `Style/BracesAroundHashParameters`
when the opening brace is before the first hash element.

```console
% rubocop -V
0.60.0 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-darwin17)

% cat example.rb
# frozen_string_literal: true

foo = Foo.new(
  { foo: 'foo',
    bar: 'bar',
    baz: 'this is the last element'}
)
```

The following difference is the execution result of `rubocop -a` command.

## Before

The last element is lost.

```diff
diff --git a/example.rb b/example.rb
index ecf9711..c9a02b8 100644
--- a/example.rb
+++ b/example.rb
@@ -1,7 +1,6 @@
 # frozen_string_literal: true

 foo = Foo.new(
-  { foo: 'foo',
-    bar: 'bar',
-    baz: 'this is the last element'}
+  foo: 'foo',
+  bar: 'bar'
 )
```

## After

Remove only the braces.

```diff
diff --git a/example.rb b/example.rb
index ecf9711..57790da 100644
--- a/example.rb
+++ b/example.rb
@@ -1,7 +1,7 @@
 # frozen_string_literal: true

 foo = Foo.new(
-  { foo: 'foo',
-    bar: 'bar',
-    baz: 'this is the last element'}
+  foo: 'foo',
+  bar: 'bar',
+  baz: 'this is the last element'
 )
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants