Join GitHub today
[Fix #3566] Add new `Metrics/BlockLength` cop. #3587
This cop checks there aren't too many lines in blocks, much like
By default the max lines has been set to 25 which seems a decent starting point as the Rubocop library passes without having to change our config file (but only due to the default excluded files).
The cop is excluded from checking the
I've left this as 2 separate commits, the first of which adds the cop, and the second of which refactors shared parts into a mixin. I'm not sure if there's a nicer way to make each cop's message work without having to have a method in each cop to pass its label through, like this.
Before submitting the PR make sure the following are checked:
I'd prefer a default of 10 - same as
Other than that, I love the new cop!
I started off thinking 10 was a good idea too until I saw how many places it failed.
Admittedly excluding it on specs and rake things helped, but there's still quite a lot. I imagine every Rails application's
Perhaps we should put this in a new issue so more people see it and can voice opinions? I imagine not many will in here.