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

[Fix #6264] Fix an incorrect autocorrect for `Layout/EmptyLineAfterGuardClause` #6284

Merged
merged 1 commit into from Sep 14, 2018

Conversation

Projects
None yet
3 participants
@koic
Copy link
Member

koic commented Sep 12, 2018

Fixes #6264.

This PR fixes an incorrect auto-correct for Layout/EmptyLineAfterGuardClause cop when if condition is after heredoc.

This problem included two problems of auto-correct related to heredoc and false positives of if condition.

So this PR fixes the following auto-correct.

raise(<<-FAIL) if true
  boop
FAIL
1

The following is the result of auto-correct.

Before

raise(<<-FAIL) if true

  boop
FAIL
1

After

raise(<<-FAIL) if true
  boop
FAIL

1

Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run rake default. It executes all tests and RuboCop for itself, and generates the documentation.
end

def heredoc?(node)
((node.respond_to?(:str_type?) && node.str_type?) ||

This comment has been minimized.

@Drenmi

Drenmi Sep 12, 2018

Collaborator

What's the case where #last_argument is not a Node? 🤔

This comment has been minimized.

@koic

koic Sep 13, 2018

Author Member

The method name #last_argument may not be representation well.
This code uses respond_to?(:heredoc?) because it possible returns SendNode or Symbol instead of StrNode.
I have not yet had a reasonable solution, but I have refactored redundant codes.

[Fix #6264] Fix an incorrect autocorrect for `Layout/EmptyLineAfterGu…
…ardClause`

Fixes #6264.

This PR fixes an incorrect auto-correct for `Layout/EmptyLineAfterGuardClause` cop
when `if` condition is after heredoc.

This problem included two problems of auto-correct related to
heredoc and false positives of `if` condition.

So this PR fixes the following auto-correct.

```ruby
raise(<<-FAIL) if true
  boop
FAIL
1
```

The following is the result of auto-correct.

## Before

```ruby
raise(<<-FAIL) if true

  boop
FAIL
1
```

## After

```ruby
raise(<<-FAIL) if true
  boop
FAIL

1
```

@koic koic force-pushed the koic:fix_false_positive_for_empty_line_after_guard_clause branch from eea3bb1 to 91f2a57 Sep 13, 2018

@bbatsov bbatsov merged commit 6d273ee into rubocop-hq:master Sep 14, 2018

23 checks passed

ci/circleci: cc-setup Your tests passed on CircleCI!
Details
ci/circleci: cc-upload-coverage Your tests passed on CircleCI!
Details
ci/circleci: documentation-checks Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-rubocop Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.2-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.2-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.2-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.3-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.3-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.3-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-rc-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-rc-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-rc-spec Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@koic koic deleted the koic:fix_false_positive_for_empty_line_after_guard_clause branch Sep 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.