We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The Layout/EmptyLineAfterGuardClause cop misbehaves in a situation such as this (very contrived) example:
# frozen_string_literal: true def weird_sum(my_array) my_array .map { |item| next unless item.positive?; item * 2 } .compact .sum end
No empty line inserted, or an empty line is inserted inside the block.
An empty line is inserted before the .compact line, resulting in a syntax error.
.compact
$ rubocop --debug --auto-correct test.rb For /home/afn/work: Default configuration from /home/afn/.rvm/gems/ruby-3.0.1/gems/rubocop-1.18.4/config/default.yml Inspecting 1 file Scanning /home/afn/work/test.rb E Offenses: test.rb:5:19: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause. .map { |item| next unless item.positive?; item * 2 } ^^^^^^^^^^^^^^^^^^^^^^^^^^ test.rb:7:5: E: Lint/Syntax: unexpected token tDOT (Using Ruby 3.0 parser; configure using TargetRubyVersion parameter, under AllCops) .compact ^ 1 file inspected, 2 offenses detected, 1 offense corrected Finished in 0.11396609200164676 seconds
Resulting file:
See above.
1.18.4 (using Parser 3.0.2.0, rubocop-ast 1.8.0, running on ruby 3.0.1 x86_64-linux)
The text was updated successfully, but these errors were encountered:
Layout/EmptyLineAfterGuardClause
[Fix rubocop#9977] Update Layout/EmptyLineAfterGuardClause to not r…
4cc6040
…egister an offense if there is another expression following the guard clause on the same line.
[Fix #9977] Update Layout/EmptyLineAfterGuardClause to not register…
984fcea
… an offense if there is another expression following the guard clause on the same line.
dvandersluis
Successfully merging a pull request may close this issue.
The Layout/EmptyLineAfterGuardClause cop misbehaves in a situation such as this (very contrived) example:
Expected behavior
No empty line inserted, or an empty line is inserted inside the block.
Actual behavior
An empty line is inserted before the
.compact
line, resulting in a syntax error.Resulting file:
Steps to reproduce the problem
See above.
RuboCop version
1.18.4 (using Parser 3.0.2.0, rubocop-ast 1.8.0, running on ruby 3.0.1 x86_64-linux)
The text was updated successfully, but these errors were encountered: