【发布时间】:2016-09-10 17:59:50
【问题描述】:
我刚刚将 RuboCop 添加到 Rails 项目并安装了 Sublime 包以在编辑器中查看 RuboCop 建议。我试图弄清楚如何从 80 个字符更改最大行长度,或者完全忽略该规则。
目前正在使用:
【问题讨论】:
标签: ruby-on-rails ruby sublimetext3 rubocop
我刚刚将 RuboCop 添加到 Rails 项目并安装了 Sublime 包以在编辑器中查看 RuboCop 建议。我试图弄清楚如何从 80 个字符更改最大行长度,或者完全忽略该规则。
目前正在使用:
【问题讨论】:
标签: ruby-on-rails ruby sublimetext3 rubocop
在您的代码中,您可以像这样禁用一堆行:
# rubocop:disable Layout/LineLength
puts "This line is lonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnng"
# rubocop:enable Layout/LineLength
或将其添加到您的 .rubocop.yml 文件以增加最大长度:
Layout/LineLength:
Max: 100
【讨论】:
.rubocop.yml 中的. 现在可以使用了,谢谢!
在项目的根目录中创建一个.rubocop.yml 文件(注意文件名中的初始.),您将有很多选项(检查 cmets 以了解用作 @987654321 的 Rubocop 版本是什么@):
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'
【讨论】:
随着 rubocop gem 版本 0.78.0 于 2019 年 18 月 12 日的最新变化,LineLength cop 从现在开始从 Metrics 部门转移到 Layout 部门。所以基本上如果有人需要禁用使用高于 0.78.0 的版本号的长行应该这样做。
# rubocop:disable Layout/LineLength
"I'm a really long line"
# rubocop:enable Layout/LineLength
还有.rubocop.yml配置改成这个。
Layout/LineLength:
Max: 100
如需获取 rubocop 更改日志,click here
【讨论】: