no-warning-comments
不允许在注释中使用指定的警告词语
❄️ 已冻结
此规则目前处于冻结状态,不接受功能请求。
开发者经常在未完成或需要审查的代码中添加注释。 最有可能的是,您希望在认为代码可以用于生产环境之前,修复或审查代码,然后删除注释。
// TODO: do something
// FIXME: this is not a good idea
规则详情
此规则报告包含在其配置中指定的任何预定义词语的注释。
选项
此规则具有一个选项对象字面量
"terms"
: 可选的要匹配的词语数组。默认为["todo", "fixme", "xxx"]
。词语匹配不区分大小写,并且是全字匹配:fix
将匹配FIX
但不匹配fixing
。词语可以由多个单词组成:really bad idea
。"location"
: 可选的字符串,用于配置在注释中检查匹配项的位置。默认为"start"
。起始位置是从第一个非装饰字符开始,忽略空格、换行符和decoration
中指定的字符。另一个值是在注释的anywhere
中匹配。"decoration"
: 可选的字符数组,当 location 为"start"
时,在注释开头处被忽略。默认为[]
。任何空格序列或来自此属性的字符都将被忽略。当 location 为"anywhere"
时,此选项将被忽略。
对于默认选项 { "terms": ["todo", "fixme", "xxx"], "location": "start" }
的错误代码示例
在 Playground 中打开
/*eslint no-warning-comments: "error"*/
function callback(err, results) {
if (err) {
console.error(err);
return;
}
}
对于默认选项 { "terms": ["todo", "fixme", "xxx"], "location": "start" }
的正确代码示例
在 Playground 中打开
/*eslint no-warning-comments: "error"*/
function callback(err, results) {
if (err) {
console.error(err);
return;
}
// NOT READY FOR PRIME TIME
// but too bad, it is not a predefined warning term
}
terms 和 location
对于选项 { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }
的错误代码示例
在 Playground 中打开
/*eslint no-warning-comments: ["error", { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }]*/
对于选项 { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }
的正确代码示例
在 Playground 中打开
/*eslint no-warning-comments: ["error", { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }]*/
// This is to do
// even not any other term
// any other terminal
/*
* The same goes for block comments
* with any other interesting term
* or fix me this
*/
装饰字符
对于选项 { "decoration": ["*"] }
的错误代码示例
在 Playground 中打开
/*eslint no-warning-comments: ["error", { "decoration": ["*"] }]*/
对于选项 { "decoration": ["/", "*"] }
的错误代码示例
在 Playground 中打开
/*eslint no-warning-comments: ["error", { "decoration": ["/", "*"] }]*/
对于选项 { "decoration": ["/", "*"] }
的正确代码示例
在 Playground 中打开
/*eslint no-warning-comments: ["error", { "decoration": ["/", "*"] }]*/
//!TODO preceded by non-decoration character
/**
*!TODO preceded by non-decoration character in a block comment
*/
何时不使用
- 如果您有一个大型代码库,该代码库的开发没有不使用此类警告词语的策略,您可能会收到数百个警告/错误,如果您无法修复所有这些警告/错误(例如,如果您没有时间这样做),这可能会适得其反,因为您可能会忽略其他警告/错误,或者习惯于其中的许多警告/错误,而不再关注它们。
- 与上述观点相同的原因:您不应配置经常使用的词语(例如,注释中使用的母语的核心部分)。
版本
此规则在 ESLint v0.4.4 中引入。