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:
There is a way to ignore cops on a per line basis. There is also a way to do it via configuration file. Run rubocop --auto-gen-config and it will generate a file that you can use to disable the offenses. The command also gives a hint on what to do to load those options.
The nice thing about disabling Rubocop within code is that you can disable and re-enable cops within a program. So, if you wanted to ignore warnings in a block of code that pertained to 'LineLength' and 'StringLiterals', you could wrap code with comments to disable/enable cops whenever you want.
RuboCop is a Ruby code style checking and code formatting tool. It aims to enforce the community-driven Ruby Style Guide.
When inspecting a certain directory (or file) given as RuboCop’s command line arguments, patterns listed under AllCops / Exclude are also inspected. If you want to apply AllCops / Exclude rules in this circumstance, add --force-exclusion to the command line argument.
Empty lines do not contribute to the relevant LOC.", and that's why RuboCop has 10 as the default limit. The subject is not entirely without debate. Some studies indicate that long methods are actually less error-prone than short ones, but you have to go with your conviction some times and not blindly follow the numbers.
The Ruby Style Guide says "Avoid methods longer than 10 LOC (lines of code). Ideally, most methods will be shorter than 5 LOC. Empty lines do not contribute to the relevant LOC.", and that's why RuboCop has 10 as the default limit. The subject is not entirely without debate.
But, if you’d like RuboCop to check files that are not included by default, you’ll need to pass them in on the command line, or to add entries for them under AllCops / Include. Remember that your configuration files override RuboCops’s defaults.
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
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With