-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
[Fix #111] Fix an incorrect autocorrect for Rails/Presence
#115
Merged
koic
merged 1 commit into
rubocop:master
from
koic:fix_incorrect_autocorrect_for_rails_presence
Aug 26, 2019
Merged
[Fix #111] Fix an incorrect autocorrect for Rails/Presence
#115
koic
merged 1 commit into
rubocop:master
from
koic:fix_incorrect_autocorrect_for_rails_presence
Aug 26, 2019
Conversation
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
koic
force-pushed
the
fix_incorrect_autocorrect_for_rails_presence
branch
from
August 24, 2019 05:13
4734c9a
to
de133ab
Compare
koic
changed the title
[Fix #111] Fix incorrect autocorrect for
[Fix #111] Fix an incorrect autocorrect for Aug 24, 2019
Rails/Presence
Rails/Presence
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
force-pushed
the
fix_incorrect_autocorrect_for_rails_presence
branch
from
August 26, 2019 05:11
de133ab
to
ce2937d
Compare
koic
added a commit
to koic/rubocop-rails
that referenced
this pull request
Aug 27, 2019
Fixes rubocop#116 and adds regression test for rubocop#115. This PR fixes an incorrect autocorrect for `Rails/Presence` when `else` branch of ternary operator is not nil. The following is a reproduction procedure. ```ruby # example.rb a.blank? ? 1 : a ``` ```console % bundle exec rubocop --only Rails/Presence -a Inspecting 1 file C Offenses: example.rb:1:1: C: [Corrected] Rails/Presence: Use a.presence instead of a.blank? ? 1 : a. a.blank? ? 1 : a ^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected ``` ```diff -a.blank? ? 1 : a +a.presence ``` This PR is auto-corrected to `a.presence || 1`.
8 tasks
koic
added a commit
to koic/rubocop-rails
that referenced
this pull request
Aug 27, 2019
Fixes rubocop#116 and adds regression tests for rubocop#115. This PR fixes an incorrect autocorrect for `Rails/Presence` when `else` branch of ternary operator is not nil. The following is a reproduction procedure. ```ruby # example.rb a.blank? ? 1 : a ``` ```console % bundle exec rubocop --only Rails/Presence -a Inspecting 1 file C Offenses: example.rb:1:1: C: [Corrected] Rails/Presence: Use a.presence instead of a.blank? ? 1 : a. a.blank? ? 1 : a ^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected ``` ```diff -a.blank? ? 1 : a +a.presence ``` This PR is auto-corrected to `a.presence || 1`.
koic
added a commit
to koic/rubocop-rails
that referenced
this pull request
Aug 27, 2019
Fixes rubocop#116 and adds regression tests for rubocop#115. This PR fixes an incorrect autocorrect for `Rails/Presence` when `else` branch of ternary operator is not nil. The following is a reproduction procedure. ```ruby # example.rb a.blank? ? 1 : a ``` ```console % bundle exec rubocop --only Rails/Presence -a Inspecting 1 file C Offenses: example.rb:1:1: C: [Corrected] Rails/Presence: Use a.presence instead of a.blank? ? 1 : a. a.blank? ? 1 : a ^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected ``` ```diff -a.blank? ? 1 : a +a.presence ``` This PR will auto-corrected to `a.presence || 1`.
koic
added a commit
to koic/rubocop-rails
that referenced
this pull request
Aug 27, 2019
Fixes rubocop#116 and adds regression tests for rubocop#115. This PR fixes an incorrect autocorrect for `Rails/Presence` when `else` branch of ternary operator is not nil. The following is a reproduction procedure. ```ruby # example.rb a.blank? ? 1 : a ``` ```console % bundle exec rubocop --only Rails/Presence -a Inspecting 1 file C Offenses: example.rb:1:1: C: [Corrected] Rails/Presence: Use a.presence instead of a.blank? ? 1 : a. a.blank? ? 1 : a ^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected ``` ```diff -a.blank? ? 1 : a +a.presence ``` This PR will auto-correct it to `a.presence || 1`.
koic
added a commit
to koic/rubocop-rails
that referenced
this pull request
Aug 31, 2019
Fixes rubocop#116 and adds regression tests for rubocop#115. This PR fixes an incorrect autocorrect for `Rails/Presence` when `else` branch of ternary operator is not nil. The following is a reproduction procedure. ```ruby # example.rb a.blank? ? 1 : a ``` ```console % bundle exec rubocop --only Rails/Presence -a Inspecting 1 file C Offenses: example.rb:1:1: C: [Corrected] Rails/Presence: Use a.presence instead of a.blank? ? 1 : a. a.blank? ? 1 : a ^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected ``` ```diff -a.blank? ? 1 : a +a.presence ``` This PR will auto-correct it to `a.presence || 1`.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #111.
This PR fixes an incorrect autocorrect for
Rails/Presence
when method arguments ofelse
branch is not enclosed in parentheses.The following is a reproduction procedure.
The auto-corrected code is a syntax error.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.