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:
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
Rails 3 - Restricting Formats for Action in Resource Routes
Detect Number of Cpus Installed
How to Pass a Custom Comparator to "Sort"
Convert String to Symbol-Able in Ruby
Is It Right to Assign Multiple Variables Like This a = B = C = D = 5
Find File Path of a Given Class
Installing Ruby 1.9.1 on Ubuntu
What Is the Use of "#!/Usr/Local/Bin/Ruby -W" at the Start of a Ruby Program
How to Read a Password from the Command Line in Ruby
Check If Two Arrays Have the Same Contents (In Any Order)
How to Get the Ip Address of My Local MAChine in Ruby
Parsing Atom & Rss in Ruby/Rails
Ruby Array to String Conversion
Failed to Build Gem Native Extension When Install Redcloth-4.2.9 Install Linux