Rubocop Linelength:如何忽略带注释的行? [英] Rubocop Linelength: How to ignore lines with comments?

查看:68
本文介绍了Rubocop Linelength:如何忽略带注释的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Rails 4应用程序时,我希望Rubocop在检查行是否过长时忽略带有注释的行(只是注释或某些带有行尾注释的代码).有办法吗?

Using a Rails 4 app I would like Rubocop to ignore lines with comments (just a comment or some code with an end of line comment) when checking if a line is to long. Is there a way to do this?

推荐答案

有一种方法可以按行忽略警察.

There is a way to ignore cops on a per line basis.

还有一种方法可以通过配置文件来实现.

There is also a way to do it via configuration file.

运行rubocop --auto-gen-config,它将生成一个文件,可用于禁用攻击.

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.

在每行的基础上,您也可以启用和禁用警察.

On a line per line basis, you can enable and disable the cops as well.

# rubocop:disable RuleByName
This is a long line 
# rubocop:enable RuleByName

您还可以一次在代码中执行多个规则.

You can also do more than one rule at a time in your code.

# rubocop:disable BlockComments, AsciiComments

通过使用内联指令,该指令仅对该指令有效 行,看起来像这样:

By using an inline directive, the directive becomes valid only for that line, and it would look like this:

# Thanks to @jnt30 for the comment!
method(argument) # rubocop:disable SomeRule, SomeOtherRule

您可以在官方手册.

要找到值得看的所有规则名称,请在rubocop配置文件中

To find all the rule names its worth looking in the rubocop config files

cyberwiz 说-当我需要规则名称而不是在文档中查找时,运行rubocop -D." 更新:现在,这是不带标志的默认行为.

cyberwiz says - "run rubocop -D when I need the rule names rather than looking in the documentation." Update: This is now the default behavior without the flag.

这篇关于Rubocop Linelength:如何忽略带注释的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆