fedest
fedest

Reputation: 1350

Rails: rubocop disable Class has too many lines error

I have a class with constants, many constants. And rubocop is complaining about the length of this Class, which I don't care how long it gets.

I want to disable rubocop's error: "Class has too many lines" but the following is not working:

# rubocop:disable ClassLength

Also, the following isn't either:

# rubocop:disable Metrics/ClassLength

What is the correct metric that I need to disable?

Upvotes: 38

Views: 45094

Answers (5)

FonchoRG
FonchoRG

Reputation: 71

Using the file .rubocop.yml you can add this code to disable it:

Metrics/ClassLength:
  Enabled: false

You can find more information about it in the rubocop configuration page

Upvotes: 4

SMAG
SMAG

Reputation: 788

when disabling, be sure to enable again

# rubocop:disable ClassLength
class LongClass
end
# rubocop:enable ClassLength

references:

  1. rubocop/lib/rubocop/cop/metrics/class_length.rb

  2. disabling-cops-within-source-code

Upvotes: 22

prograils
prograils

Reputation: 2376

in .rubocop.yml:

Metrics/MethodLength:
  Max: 1000

Upvotes: 19

Dorian
Dorian

Reputation: 23939

Or in .rubocop.yml:

Metrics/ClassLength:
  Exclude:
    - "path/to/your/file.rb"

Upvotes: 18

AnoE
AnoE

Reputation: 8345

Try

class Xzy  # rubocop:disable Metrics/ClassLength

Upvotes: 47

Related Questions