Ruby-on-rails RuboCop:行太长 ← 如何忽略?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37228624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:24:31  来源:igfitidea点击:

RuboCop: Line is too long ← How to Ignore?

ruby-on-railsrubysublimetext3rubocop

提问by Abram

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.

我刚刚将 RuboCop 添加到 rails 项目并安装了 Sublime 包,以便在编辑器中查看 RuboCop 建议。我想弄清楚如何从 80 个字符更改最大行长度,或者完全忽略该规则。

Currently in use:

目前使用中:

回答by Stéphane Bruckert

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.ymlfile to increase the max length:

或者将其添加到您的.rubocop.yml文件中以增加最大长度:

Metrics/LineLength:
  Max: 100

回答by Alter Lagos

Creating a .rubocop.ymlfile (keep an eye on the initial .in the filename) in the root of your project, you'll have a bunch of options:

在项目的根目录中创建一个.rubocop.yml文件(注意.文件名中的首字母),您将有很多选项:

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'

回答by Semih Arslano?lu

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 gem 版本 0.78.0 在 18-12-2019 的最新变化,从现在起 LineLength cop 从度量部门转移到布局部门。所以基本上如果有人需要使用高于 0.78.0 的版本号禁用长行应该这样做。

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

Also .rubocop.ymlconfiguration is changed to this.

.rubocop.yml配置改变了这一点。

Layout/LineLength:
  Max: 100

For reaching rubocop change logs, click here

要获取 rubocop 更改日志,请单击此处