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

Allow module in Metrics/BlockLength ExcludedMethods directive #4257

Closed
jcoyne opened this issue Apr 10, 2017 · 2 comments
Closed

Allow module in Metrics/BlockLength ExcludedMethods directive #4257

jcoyne opened this issue Apr 10, 2017 · 2 comments

Comments

@jcoyne
Copy link

jcoyne commented Apr 10, 2017

My rubocop.yml:

Metrics/BlockLength:
  ExcludedMethods: ['included', 'SimpleForm.setup', 'Gem::Specification.new']  

But when I run rubocop, it still trips on:

config/initializers/simple_form.rb:3:1: C: Metrics/BlockLength: Block has too many lines. [32/25]
SimpleForm.setup do |config| ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Using rubocop 0.48.1

It does work when I switch to:

  ExcludedMethods: ['included', 'setup', 'new']  

But that's less tightly scoped than I'd prefer.

@asaletnik
Copy link

+1

@pocke
Copy link
Collaborator

pocke commented Jan 21, 2018

Ref #4967

akhramov pushed a commit to akhramov/rubocop that referenced this issue Apr 14, 2018
…thods`

Currently `Metrics/BlockLength` cop has `ExcludedMethods`
configuration option, which only allows to specify method names,
without a module, i.e. the following works:
```yaml
Metrics/BlockLength:
  ExcludedMethods: ['new']
```
But the following doesn't:
```yaml
Metrics/BlockLength:
  ExcludedMethods: ['Gem::Specification.new']
```

This change tweaks `Cop::Metrics::BlockLength#on_block` so it looks
not on the method being called, but rather on the whole
`SendNode`. This preserves current behavior, but also lets specifying
more interesting constructs like `Gem::Specification.new` or even
method chains (`foo.bar.baz`).
akhramov pushed a commit to akhramov/rubocop that referenced this issue Apr 14, 2018
bbatsov added a commit to akhramov/rubocop that referenced this issue Apr 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants