Fix autocorrection for Cop/LineBreakAfterGuardClauses
What does this MR do and why?
This commit fixes the autocorrection functionality for
Cop/LineBreakAfterGuardClauses
and improves its spec coverage.
Coverage
Before 99.51% | After 99.83% |
---|---|
https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/jobs/3601173860 | https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/jobs/3601473389 |
How to verify locally
- Create
foo.rb
with
# frozen_string_literal: true
def foo
return if foo
bar
end
- Switch to
master
and run:
bundle exec rubocop --autocorrect --only Cop/LineBreakAfterGuardClauses foo.rb
Inspecting 1 file
C
Offenses:
foo.rb:3:3: C: Cop/LineBreakAfterGuardClauses: Add a line break after guard clauses
return if foo
^^^^^^^^^^^^^
1 file inspected, 1 offense detected
-
Verify that
foo.rb
was not corrected❌ -
Switch to this branch and run:
bundle exec rubocop --autocorrect --only Cop/LineBreakAfterGuardClauses foo.rb
Inspecting 1 file
C
Offenses:
foo.rb:3:3: C: [Corrected] Cop/LineBreakAfterGuardClauses: Add a line break after guard clauses
return if foo
^^^^^^^^^^^^^
1 file inspected, 1 offense detected, 1 offense corrected
- Verify that
foo.rb
got corrected and a newline was added✅
# frozen_string_literal: true
def foo
return if foo
bar
end
Edited by Peter Leitzen