bbatsov/rubocop — pull request #1345 by smangelsdorf (2014-09-24 10:54:00+00:00)
Title: Allow DSL methods to be checked by some Metrics cops

New feature for consideration.

The `MethodLength`, `CyclomaticComplexity` and `PerceivedComplexity` cops haven't been able to check DSL-style methods in RSpec, Sinatra, and others. Especially in the case of Sinatra apps, [the content in the DSL](http://www.sinatrarb.com/intro.html#Routes) is the most important part of the app, so it's important that this is checkable.

This change adds support for a configurable list of DSL methods which are treated as methods when running those cops. To be checked, the methods must be invoked with a block and no receiver, and then the contents of the block are considered the "body" of the method.

I gave this a trial run using the following configuration, appended to `spec/.rubocop.yml` in the RuboCop project:

```yaml
Metrics/MethodLength:
DSLMethods:
- it

Metrics/CyclomaticComplexity:
Max: 2
DSLMethods:
- it
```

Results can be seen at: https://gist.github.com/smangelsdorf/b1b13218e67703380a3c (there are a few stray violations in there because I'm overriding the CyclomaticComplexity Max defined in `.rubocop_todo.yml`)

I'm not sold on having the `DSLMethods` config option duplicated three times. The only other option I could come up with was to set it at the `AllCops` level in `default.yml`, but that seemed perhaps a bit extreme. Any thoughts welcomed.