Loading
Check blocks with _1 and it in RSpec/EmptyLineAfterSharedExample
What does this MR do?
Makes RSpec/EmptyLineAfterSharedExample check shared example blocks that use numbered parameters (_1) or Ruby 3.4's it. Until now it skipped them.
Related to #94 (closed), which fixed the same bug in Cop/AvoidReturnFromBlocks and RSpec/ExampleStartingCharacter. This is the last custom cop with it.
it_behaves_like 'does this' do |x| # offense, before and after
x
end
it 'does that' do
end
it_behaves_like 'does this' do # offense only after this MR
_1 # (same with `it`, or with `shared_examples`)
end
it 'does that' do
endImpact: projects using gitlab-styles may get new offenses for shared example blocks that use _1 or it. The cop autocorrects them.
Cause and fix
- The cop sends
numblockanditblocknodes toon_block, but itsshared_examplesmatcher only matched(block ...), so it never yielded for them. - The fix uses
(any_block ...)in both block branches, the same as the #94 (closed) fix forRSpec/ExampleStartingCharacter(c716fd49). - The cop's other helpers,
last_child?andmissing_separating_line_offense, already work with any block type, so the autocorrect is unchanged.
Specs
New examples for it_behaves_like and shared_examples blocks, with offense and correction, run with _1, and with it under :ruby34. Against master's version of the cop, 4 of them fail.