Add new RSpec/EmptyLineAfterSharedInclusion cop#2165
Conversation
35a6802 to
1e7e5d9
Compare
There was a problem hiding this comment.
Thank you for the contribution 👍
Never mind the failing CI – I’ve opened a bug report with RuboCop: rubocop/rubocop#15010
|
cc @pirj |
|
At a glance - would the cop’s code benefit from using the EmptyLineSeparation mixin? |
Seems to me it would, nice! Will look into this later. |
1e7e5d9 to
587c1fa
Compare
|
Tried on real-world-rspec: etc Total: 452 offences, I’ve only glanced over those ones above. Some of those feel off. |
|
Disregard the Edge RuboCop failure. It’s another false positive, and I have opened an issue to get it fixed: rubocop/rubocop#15028 |
|
Could you be more specific about which ones feel off? Personally, I don't agree with this being flagged: it_behaves_like 'cachable response'
it_behaves_like 'language-dependent' if TestEndpoints::LANGUAGE_DEPENDENT.include?(endpoint) |
|
After having a fresh look all offences I’ve posted (except the las one that you’ve highlighted, too) are totally reasonable. There’s one where include_context comes before Can you please check other offences to try to see if there are more edge cases? |
587c1fa to
7a6266d
Compare
|
I've updated the cop's logic to take conditionals into account. Now the number of offenses on real-world-rspec is down to 448. |
7a6266d to
40792a3
Compare
| # # bad | ||
| # RSpec.describe User do | ||
| # it_behaves_like 'a sortable' | ||
| # it { does_something } | ||
| # end |
There was a problem hiding this comment.
Should we also show the corresponding "good" version of this example?
| elsif conditional_inclusion?(child) | ||
| next if consecutive_inclusion?(child) | ||
|
|
||
| check_conditional_inclusion(child) |
There was a problem hiding this comment.
This is a lot of extra work for almost the same check as lines 62–67, but after looking closer I cannot find a better way to implement it. At least not without changing EmptyLineSeparation more than I like.
2364aeb to
9154f4c
Compare
Add a new
RSpec/EmptyLineAfterSharedInclusioncop that checks for an empty line after shared example inclusion (include_context,include_examples,it_behaves_like,it_should_behave_like), or a group of them.Modeled after
Layout/EmptyLinesAfterModuleInclusionfrom rubocop - consecutive inclusions can be grouped together without empty lines between them, but an empty line is required after the last one before other code.Before submitting the PR make sure the following are checked:
master(if not - rebase it).CHANGELOG.mdif the new code introduces user-observable changes.bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).If you have created a new cop:
config/default.yml.Enabled: pendinginconfig/default.yml.Enabled: truein.rubocop.yml.VersionAdded: "<<next>>"indefault/config.yml.If you have modified an existing cop's configuration options:
VersionChanged: "<<next>>"inconfig/default.yml.