Skip to content
New issue

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

Add cop for block length #3566

Closed
aidalgol opened this issue Oct 2, 2016 · 4 comments
Closed

Add cop for block length #3566

aidalgol opened this issue Oct 2, 2016 · 4 comments
Labels
feature request good first issue Easy task, suitable for newcomers to the project hacktoberfest

Comments

@aidalgol
Copy link

aidalgol commented Oct 2, 2016

I would like a cop like Metrics/MethodLength but for blocks (as in do...end or {...}). I think this would be especially useful when using frameworks like Sinatra or Rake that heavily use methods with block parameters. (namespace, task, etc. in Rake; get, post, etc. with Sinatra.)

I am trying to implement this myself, but I'm getting a bit lost around AST-node pattern-matching.

RuboCop version

$ rubocop -V
0.43.0
@bbatsov bbatsov added feature request good first issue Easy task, suitable for newcomers to the project labels Oct 2, 2016
@bbatsov
Copy link
Collaborator

bbatsov commented Oct 2, 2016

You don't really need any pattern matching to write this. You just have to process on_block method invocations.

savef added a commit to savef/rubocop that referenced this issue Oct 8, 2016
This cop checks there aren't too many lines in blocks, much like `Metric/MethodLength` checks for too many lines in methods.

Also removed the splatted additional args from CodeLength#check_code_length, I don't think they've been necessary since the old `check` method was refactored into that method.
@bbatsov bbatsov closed this as completed in 96f308b Oct 8, 2016
@aidalgol
Copy link
Author

aidalgol commented Oct 8, 2016

Awesome, thanks for implementing this! 😀

alexjfisher added a commit to alexjfisher/modulesync_config that referenced this issue Oct 14, 2016
`Metric/BlockLength` is a new cop in rubocop 0.44.
rubocop/rubocop#3566

All puppet type definitions occur in blocks that are almost always
longer than 25 lines.  I don't see much benefit in having the cop
enabled, and then having to disable it with control comments instead.

Signed-off-by: Alexander Fisher <alex@linfratech.co.uk>
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
This cop checks there aren't too many lines in blocks, much like `Metric/MethodLength` checks for too many lines in methods.

Also removed the splatted additional args from CodeLength#check_code_length, I don't think they've been necessary since the old `check` method was refactored into that method.
@sullerandras
Copy link

Is there an easy way to disable this cop for RSpec tests but keep it enabled for all other codes?

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 20, 2016

You can exclude your rspec tests dir from this cop's config. Or place a different .rubocop.yml in your rspec dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request good first issue Easy task, suitable for newcomers to the project hacktoberfest
Projects
None yet
Development

No branches or pull requests

3 participants