-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 false positive for Style/EmptyLineAfterGuardClause
#5720
Fix false positive for Style/EmptyLineAfterGuardClause
#5720
Conversation
2efaf18
to
cf29667
Compare
I guess thsi cop also allows the following code. def foo
raise ArgumentError, <<-MSG unless path
Must be called with mount point
MSG
bar
end Should the cop allow it? I guess the cop should add an offense to the code since there are no new lines between the guard clause and the next statement. But it is an exceptional case, so I'm not sure should the cop do. I think we should decide the behaviour, and add a test case for this code. |
Guard clauses after heredocs are extremely hard to spot IMO. I wonder if it would be wise to discourage those. As for this example - it seems to me there should be some blank line in this case. |
I agree. |
I also noticed this cop has been placed in the wrong namespace. Should be in |
I also think the example code @pocke showed is false negative. I'll look it in detail later.
Yep. I think so too. Certainly this cop will not be |
Related rubocop#5679. This PR fixes a false positive for Style/EmptyLineAfterGuardClause when guard clause is after heredoc. ## Reproduction code ```ruby def foo raise ArgumentError, <<-MSG unless path Must be called with mount point MSG bar end ``` :memo: I found this false positivity below. https://github.com/rails/rails/blob/v5.2.0.rc2/actionpack/lib/action_dispatch/routing/mapper.rb#L614-L622 ## Expected behavior No offenses. ## Actual behavior and Steps to reproduce the problem ```console % 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.4, running on ruby 2.5.0 x86_64-darwin17) ``` This PR fixes the above false positive.
cf29667
to
b4a79d5
Compare
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.
Follow up of #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 #5720.
I intended to wrote rubocop#5720 in "Bug fixes" section, but it probably moved to an unintended "Changes" section at the timing of rebasing.
I intended to wrote #5720 in "Bug fixes" section, but it probably moved to an unintended "Changes" section at the timing of rebasing.
Follow up of rubocop#5720 (comment). This PR moves `Style/EmptyLineAfterGuardClause` cop to `Layout` department. I remember about the proposal that this cop name `EmptyLinesAroundGuardClause` is good, however I'm not sure about it. On the other hand, since I think that this cop should be in the `Layout` department, so this PR moves the department.
Follow up of #5720 (comment). This PR moves `Style/EmptyLineAfterGuardClause` cop to `Layout` department. I remember about the proposal that this cop name `EmptyLinesAroundGuardClause` is good, however I'm not sure about it. On the other hand, since I think that this cop should be in the `Layout` department, so this PR moves the department.
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.
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.
Related #5679.
This PR fixes a false positive for Style/EmptyLineAfterGuardClause when guard clause is after heredoc.
Reproduction code
📝 I found this false positivity below.
https://github.com/rails/rails/blob/v5.2.0.rc2/actionpack/lib/action_dispatch/routing/mapper.rb#L614-L622
Expected behavior
No offenses.
Actual behavior and Steps to reproduce the problem
RuboCop version
This PR fixes the above false positive.
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.
rake default
orrake parallel
. It executes all tests and RuboCop for itself, and generates the documentation.