RuboCop: Line is too long <— How to Ignore

给你一囗甜甜゛ 提交于 2019-11-27 10:04:22

问题


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:

  • RuboCop (gem)
  • Sublime RuboCop
  • SublimeLinter-rubocop

回答1:


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

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

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

Metrics/LineLength:
  Max: 100



回答2:


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:

Metrics/LineLength:
  # 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'


来源:https://stackoverflow.com/questions/37228624/rubocop-line-is-too-long-how-to-ignore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!