我刚把RuboCop添加到一个rails项目中,并安装了Sublime插件,以便在编辑器中查看RuboCop的建议。我正在尝试找出如何将最大行长度从80个字符更改为其他值,或者完全忽略此规则。
当前使用的工具:
我刚把RuboCop添加到一个rails项目中,并安装了Sublime插件,以便在编辑器中查看RuboCop的建议。我正在尝试找出如何将最大行长度从80个字符更改为其他值,或者完全忽略此规则。
当前使用的工具:
在你的代码中,你可以这样禁用一堆行:
# rubocop:disable Layout/LineLength
puts "This line is lonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnng"
# rubocop:enable Layout/LineLength
将以下内容添加到您的 .rubocop.yml
文件中,以增加最大长度:Layout/LineLength:
Max: 100
创建一个.rubocop.yml
文件(注意文件名中的初始.
)并将其放置在项目根目录下,您将有一堆选项(检查注释以查看您使用的Rubocop版本作为处理LineLength
的方法已更改):
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 年 12 月 18 日的最新更改,现在 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的更改日志,请点击此处
您可以查看此链接以禁用单行的复制。https://dev59.com/MVEG5IYBdhLWcg3wWbL5#67450682
示例:
puts "This line is lonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnng" # rubocop:disable Layout/LineLength
.rubocop.yml
中加上.
了。现在它可以工作了,谢谢! - Abram