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

Not safe refactor when run with rubocop -R -a --safe #111

Closed
zw963 opened this issue May 21, 2019 · 3 comments · Fixed by #115
Closed

Not safe refactor when run with rubocop -R -a --safe #111

zw963 opened this issue May 21, 2019 · 3 comments · Fixed by #115
Labels
bug Something isn't working

Comments

@zw963
Copy link

zw963 commented May 21, 2019

image

new code will result in syntax error.

 ╰─ $ rubocop -V
0.69.0 (using Parser 2.6.3.0, running on ruby 2.6.2 x86_64-linux)

Thank

@stale
Copy link

stale bot commented Aug 19, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@zw963
Copy link
Author

zw963 commented Aug 19, 2019

Anyone help on this issue?

image

This new code is syntax error.

@koic koic transferred this issue from rubocop/rubocop Aug 19, 2019
@koic koic added the bug Something isn't working label Aug 19, 2019
koic added a commit to koic/rubocop-rails that referenced this issue Aug 24, 2019
Fixes rubocop#111.

This PR fixes incorrect autocorrect for `Rails/Presence`  when method
arguments of `else` branch is not enclosed in parentheses.

The following is a reproduction procedure.

```console
% cat example.rb
if value.present?
  value
else
  do_something value
end
```

```console
% bundle exec rubocop -a --only Rails/Presence
Inspecting 1 file
E

Offenses:

example.rb:1:1: C: [Corrected] Rails/Presence: Use value.presence ||
do_something value instead of if value.present?
  value
else
  do_something value
end.
if value.present? ...
^^^^^^^^^^^^^^^^^
example.rb:1:32: E: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter,
under AllCops)
value.presence || do_something value
                               ^^^^^

1 file inspected, 2 offenses detected, 1 offense corrected
```

```console
% cat example.rb
value.presence || do_something value
```

The auto-corrected code is a syntax error.

```console
% ruby example.rb
example.rb:3: syntax error, unexpected local variable or method,
expecting `do' or '{' or '('
....presence || do_something value
```
koic added a commit to koic/rubocop-rails that referenced this issue Aug 24, 2019
Fixes rubocop#111.

This PR fixes an incorrect autocorrect for `Rails/Presence` when method
arguments of `else` branch is not enclosed in parentheses.

The following is a reproduction procedure.

```console
% cat example.rb
if value.present?
  value
else
  do_something value
end
```

```console
% bundle exec rubocop -a --only Rails/Presence
Inspecting 1 file
E

Offenses:

example.rb:1:1: C: [Corrected] Rails/Presence: Use value.presence ||
do_something value instead of if value.present?
  value
else
  do_something value
end.
if value.present? ...
^^^^^^^^^^^^^^^^^
example.rb:1:32: E: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter,
under AllCops)
value.presence || do_something value
                               ^^^^^

1 file inspected, 2 offenses detected, 1 offense corrected
```

```console
% cat example.rb
value.presence || do_something value
```

The auto-corrected code is a syntax error.

```console
% ruby example.rb
example.rb:3: syntax error, unexpected local variable or method,
expecting `do' or '{' or '('
....presence || do_something value
```
koic added a commit to koic/rubocop-rails that referenced this issue Aug 26, 2019
Fixes rubocop#111.

This PR fixes an incorrect autocorrect for `Rails/Presence` when method
arguments of `else` branch is not enclosed in parentheses.

The following is a reproduction procedure.

```console
% cat example.rb
if value.present?
  value
else
  do_something value
end
```

```console
% bundle exec rubocop -a --only Rails/Presence
Inspecting 1 file
E

Offenses:

example.rb:1:1: C: [Corrected] Rails/Presence: Use value.presence ||
do_something value instead of if value.present?
  value
else
  do_something value
end.
if value.present? ...
^^^^^^^^^^^^^^^^^
example.rb:1:32: E: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter,
under AllCops)
value.presence || do_something value
                               ^^^^^

1 file inspected, 2 offenses detected, 1 offense corrected
```

```console
% cat example.rb
value.presence || do_something value
```

The auto-corrected code is a syntax error.

```console
% ruby example.rb
example.rb:3: syntax error, unexpected local variable or method,
expecting `do' or '{' or '('
....presence || do_something value
```
@koic koic closed this as completed in #115 Aug 26, 2019
koic added a commit that referenced this issue Aug 26, 2019
…_presence

[Fix #111] Fix an incorrect autocorrect for `Rails/Presence`
@koic
Copy link
Member

koic commented Aug 26, 2019

RuboCop Rails 2.3.1 has been released to resolve this issue. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants