93

I just added RuboCop to a rails project and installed the Sublime package to see RuboCop suggestions in the editor. I'm trying to figure out how to change the maximum line length from 80 characters, or just ignore the rule completely.

Currently in use:

Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
Abram
  • 39,950
  • 26
  • 134
  • 184

4 Answers4

140

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
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
  • 1
    Where do I put this? – Abram May 14 '16 at 15:46
  • 1
    So I copied this file https://github.com/bbatsov/rubocop/blob/master/config/default.yml and made the change and restarted sublime, but still see the issue.. – Abram May 14 '16 at 15:50
  • 3
    Ah, I see where I went wrong. I forgot the `.` in `.rubocop.yml` Got it working now thanks! – Abram May 14 '16 at 15:52
  • I prefer the Exclude: option over the Max: option if you prefer to make the change in the .yml instead of locally. As the Max changes the rule globally and the Exclude allows you to manage the few snowflake exceptions. When it becomes more than a few, that is when I feel refactoring needs to take place. If refactoring can not help, that is when I would consider editing the Max: option. – SMAG Dec 04 '18 at 19:36
75

Creating a .rubocop.yml file (keep an eye on the initial . in the filename) in the root of your project, you'll have a bunch of options (check comments for what's your Rubocop version used as the way to handle LineLength has changed):

Metrics/LineLength: # for Rubocop < 0.78.0
Layout/LineLength: # for Rubocop >= 0.78.0
  # This will disable the rule completely, regardless what other options you put
  Enabled: false
  # Change the default 80 chars limit value
  Max: 120
  # If you want the rule only apply to a specific folder/file
  Include:
    - 'app/**/*'
  # If you want the rule not to apply to a specific folder/file
  Exclude:
    - 'db/schema.rb'
Alter Lagos
  • 12,090
  • 1
  • 70
  • 92
7

With latest changes at rubocop gem version 0.78.0 at 18-12-2019, from now on LineLength cop move from Metrics department to Layout department. So basically if any one need to disable long lines with using version number higher than 0.78.0 should do it like this.

# rubocop:disable Layout/LineLength
  "I'm a really long line"
# rubocop:enable Layout/LineLength

Also .rubocop.yml configuration is changed to this.

Layout/LineLength:
  Max: 100

For reaching rubocop change logs, click here

Semih Arslanoglu
  • 1,069
  • 5
  • 20
  • 23
1

You can check this out for disabling the cop for a single line. https://stackoverflow.com/a/67450682/9249670

Example:

puts "This line is lonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnng" # rubocop:disable Layout/LineLength
Pramod Itagi
  • 191
  • 6