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

Comments

Projects
None yet
3 participants
@aidalgol

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

This comment has been minimized.

Show comment
Hide comment
@bbatsov

bbatsov Oct 2, 2016

Collaborator

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

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

[Fix rubocop-hq#3566] Add new `Metrics/BlockLength` cop.
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.

savef added a commit to savef/rubocop that referenced this issue Oct 8, 2016

[Fix rubocop-hq#3566] Add new `Metrics/BlockLength` cop
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 in 96f308b Oct 8, 2016

@aidalgol

This comment has been minimized.

Show comment
Hide comment
@aidalgol

aidalgol Oct 8, 2016

Awesome, thanks for implementing this! 😀

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

Disable Metric/BlockLength cop
`Metric/BlockLength` is a new cop in rubocop 0.44.
rubocop-hq/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 added a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016

[Fix rubocop-hq#3566] Add new `Metrics/BlockLength` cop
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

This comment has been minimized.

Show comment
Hide comment
@sullerandras

sullerandras Oct 20, 2016

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

sullerandras commented Oct 20, 2016

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

@bbatsov

This comment has been minimized.

Show comment
Hide comment
@bbatsov

bbatsov Oct 20, 2016

Collaborator

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

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