Add new cop Style/EndlessMethod.#9281
Conversation
5d2f559 to
ae0e664
Compare
|
The documentation check failure is already fixed in #9276 (I can cherry-pick the fix commit into here as well, or once that PR is merged I'll rebase). |
ae0e664 to
6621568
Compare
|
The cop looks solid overall, but I'm wondering if this should be a standalone cop or some configuration of the |
|
After getting this feedback from @mame I'm thinking the cop should actually be based on it. We can have two supported styles:
In light of this, you can forget about my suggestion to merge this cop with |
|
Just to avoid the eventual bikeshed 😅 what are we going to define the allowed default case as? (I probably won't get to this for at least a couple days but I might have time who knows). |
|
I was thinking by default we can allow only single-line endless methods and refine the definition later to potentially account for definition simplicity and side-effects (e.g. based on configurable list of side-effect producing methods). |
|
Totally agree. I’ll make it happen. |
6621568 to
729cd48
Compare
|
@bbatsov I've redone this cop based on the above comments. I removed the changes to The styles I ended up with are |
I like this better name. I think that |
|
Yeah, I agree. Other than this, the cop seems solid to me. |
729cd48 to
883d581
Compare
883d581 to
02e4909
Compare
Follow rubocop#9281 (comment). This PR fixes a typo for `Style/SingleLineMethods`. `EnforcedStyle: allow` -> `EnforcedStyle: allow_single_line`
Follow #9281 (comment). This PR fixes a typo for `Style/SingleLineMethods`. `EnforcedStyle: allow` -> `EnforcedStyle: allow_single_line`
Style/EndlessMethodby default enforces that endless methods definitions must be on a single line (EnforcedStyle: allow). It can also be configured to disallow endless method definitions (EnforcedStyle: disallow), or to allow every endless method regardless of lines (EnforcedStyle: allow_always).This cop (obviously) only applies if
TargetRubyVersionis at least 3.0.There is a style guide issue open for this: rubocop/ruby-style-guide#858.
Before submitting the PR make sure the following are checked:
[Fix #issue-number](if the related issue exists).master(if not - rebase it).bundle exec rake default. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.mdif the new code introduces user-observable changes. See changelog entry format for details.