Rubocop: Line Is Too Long ← How to Ignore

RuboCop: Line is too long ← How to Ignore?

In your code, you can disable a bunch of lines like this:

# rubocop:disable Layout/LineLength
puts "This line is lonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnng"
# rubocop:enable Layout/LineLength

Or add this to your .rubocop.yml file to increase the max length:

Layout/LineLength:
Max: 100

Rubocop - disable long length for commented code

Layout/LineLength:
Max: 150 (for example)

or disable this cop at all

Layout/LineLength:
Enabled: false

or there is an option to ignore lines which start from certain character:

Metrics/LineLength:
Max: 80
IgnoredPatterns: ['(\A|\s)#']

How to fix line is too long error given by lint command

Took me a while but fixed it

@abc = @def.model_name.where(
id: @ghi.id).sum(:jkl) unless @ghi.blank?

What to do with a key hashed line is too long for rubocop?

I'd go for (Ruby 2.3+)

contact_params.dig(
:menucontact_attributes,
:paragraphs_attributes,
'0',
:picture
)

Keep in mind that unlike your version, this won't blow up if any of these attributes is not present.

Rubocop line is too long and Use new Ruby 1.9 hash syntax

I had used this gem. You can use like the below:

Sample Image

Rubocop, how to Disable/Enable cops on blocks of code

I answer my question because it is always very difficult for me to find the reference to this solution:

# rubocop:disable Metrics/MethodLength
def my_code
..
end
# rubocop:enable Metrics/MethodLength

Same for multiple cops:

# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def my_code
..
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength

Documentation: https://docs.rubocop.org/rubocop/configuration.html#disabling-cops-within-source-code



Related Topics



Leave a reply



Submit