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 incorrect offense for Style/EmptyLineAfterGuardClause #5760

Merged

Conversation

koic
Copy link
Member

@koic koic commented Apr 10, 2018

Follow up of #5720 (comment).

This PR fixes incorrect offense location for Style/EmptyLineAfterGuardClause when guard clause is after heredoc argument.

Reproduction code

def foo
  raise ArgumentError, <<-MSG unless path
    Must be called with mount point
  MSG
  bar
end

Expected behavior

% rubocop /tmp/example.rb --only Style/EmptyLineAfterGuardClause
Inspecting 1 file
C

Offenses:

/tmp/example.rb:4:1: C: Style/EmptyLineAfterGuardClause: Add empty line
after guard clause.
  MSG
^^^^^

1 file inspected, 1 offense detected

Actual behavior and Steps to reproduce the problem

% rubocop /tmp/example.rb --only Style/EmptyLineAfterGuardClause
Inspecting 1 file
C

Offenses:

/tmp/example.rb:2:3: C: Style/EmptyLineAfterGuardClause: Add empty line
after guard clause.
  raise ArgumentError, <<-MSG unless path
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected

RuboCop version

% rubocop -V
0.54.0 (using Parser 2.5.0.5, running on ruby 2.5.1 x86_64-darwin17)

Also, this PR will fix bugs included in changes at #5720.


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 or rake parallel. It executes all tests and RuboCop for itself, and generates the documentation.

Follow up of rubocop#5720 (comment).

This PR fixes incorrect offense location for `Style/EmptyLineAfterGuardClause` when
guard clause is after heredoc argument.

## Reproduction code

```ruby
def foo
  raise ArgumentError, <<-MSG unless path
    Must be called with mount point
  MSG
  bar
end
```

## Expected behavior

```console
% rubocop /tmp/example.rb --only Style/EmptyLineAfterGuardClause
Inspecting 1 file
C

Offenses:

/tmp/example.rb:4:1: C: Style/EmptyLineAfterGuardClause: Add empty line
after guard clause.
  MSG
^^^^^

1 file inspected, 1 offense detected
```

## Actual behavior and Steps to reproduce the problem

```
% rubocop /tmp/example.rb --only Style/EmptyLineAfterGuardClause
Inspecting 1 file
C

Offenses:

/tmp/example.rb:2:3: C: Style/EmptyLineAfterGuardClause: Add empty line
after guard clause.
  raise ArgumentError, <<-MSG unless path
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected
```

## RuboCop version

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

Also, this PR will fix bugs included in changes at rubocop#5720.
@bbatsov bbatsov merged commit c51dcbe into rubocop:master Apr 11, 2018
@koic koic deleted the fix_false_negative_empty_line_after_guard_clause branch April 11, 2018 17:03
koic added a commit to koic/rubocop that referenced this pull request Aug 30, 2018
This PR enables `Layout/EmptyLineAfterGuardClause` cop by default.

This cop has been introduced by rubocop#5522, with setting that is
disabled by default. After that, I improved this cop by
rubocop#5679, rubocop#5700, rubocop#5720, and rubocop#5760.

I think that this cop can be enabled by default as the background
of the issue rubocop#5376.

And this PR applies auto-correction using this cop.
bbatsov pushed a commit that referenced this pull request Aug 30, 2018
This PR enables `Layout/EmptyLineAfterGuardClause` cop by default.

This cop has been introduced by #5522, with setting that is
disabled by default. After that, I improved this cop by
#5679, #5700, #5720, and #5760.

I think that this cop can be enabled by default as the background
of the issue #5376.

And this PR applies auto-correction using this cop.
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 this pull request may close these issues.

None yet

2 participants