Rubocop: Add cop for block length

Created on 2 Oct 2016  路  4Comments  路  Source: rubocop-hq/rubocop

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
feature request good first issue hacktoberfest

Most helpful comment

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

All 4 comments

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

Awesome, thanks for implementing this! :grinning:

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

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

Was this page helpful?
0 / 5 - 0 ratings