forked from rubocop/rubocop-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ```
- Loading branch information
Showing
3 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters