【发布时间】:2015-09-06 00:13:32
【问题描述】:
这是我尝试设置 ESLint's new-cap 规则以接受 "S" 作为允许的函数名称:
/*eslint new-cap : [capIsNewExceptions : ["S"]] */
var S = require("string");
var lines = S(text).lines(); // <-- ESLint still gives a warning for cap 'S'!
如前所述,我的 ESLint 解析器(在 IntelliJ 中)继续给我new-cap 警告。
我已尝试谨慎申请ESLint documentation。
从here,我看到一个示例规则,如下所示:/*eslint quotes: [2, "double"], curly: 2*/,其中我收集到 quotes 和 curly 规则正在设置,quotes 规则包含两个选项,因此包含在括号中,因为文档说If a rule has additional options, you can specify them using array literal syntax(它在示例上方说这个)。
然后,从the actual documentation for new-cap,我发现capIsNewExceptions 是作为选项提供的,并且该选项的值应该是所需函数名称的数组 - 就像我在上面的代码中尝试做的那样.
但它不起作用。我仍然收到 ESLint 警告。
在用于 ESLint 的 Javascript 文件中,支持为 new-cap 规则自定义 capIsNewExceptions 选项的正确语法是什么?
【问题讨论】:
-
这是一个很好的规则——为什么不遵守呢?当需要
new的东西时,请使用大写字母。否则,小写(对于函数、对象等)? -
@Cymen 我认为这是一个非常好的例外,也是
NodeString库的标准用法。 (见npmjs.com/package/string#node-js) -
这绝对是主观的,但我倾向于将
string用于该库。
标签: javascript eslint