Rubocop Line Length: How to Ignore Lines with Comments

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)#']

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, 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

Remove rubocop comments from Yardoc documentation

To disable rubocop directives in the code from appearing in YARDOC documentation insert a newline after the comment. e.g.

# rubocop:disable Metrics/AbcSize

# Converts the object into textual markup given a specific format.
#
# @param format [Symbol] the format type, `:text` or `:html`
# @return [String] the object converted into the expected format.
def to_format(format = :html)
# format the object
end

If a Rubocop rule is disabled in-line does it need to be re-enabled

In-line config is applied to the given file only (just tested it).

Rails: rubocop disable Class has too many lines error

Try

class Xzy  # rubocop:disable Metrics/ClassLength

Rails: rubocop disable Class has too many lines error

Try

class Xzy  # rubocop:disable Metrics/ClassLength


Related Topics



Leave a reply



Submit