# 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"
:当位置为"start"
时,在注释开头忽略的可选字符数组。默认为[]
。忽略此属性中的任何空格序列或字符。当位置为"anywhere"
时,此选项将被忽略。
默认 { "terms": ["todo", "fixme", "xxx"], "location": "start" }
选项的错误代码示例:
/*eslint no-warning-comments: "error"*/
/*
FIXME
*/
function callback(err, results) {
if (err) {
console.error(err);
return;
}
// TODO
}
默认 { "terms": ["todo", "fixme", "xxx"], "location": "start" }
选项的正确代码示例:
/*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 and location
{ "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }
选项的错误代码示例:
/*eslint no-warning-comments: ["error", { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }]*/
// TODO: this
// todo: this too
// Even this: TODO
/*
* The same goes for this TODO comment
* Or a fixme
* as well as any other term
*/
{ "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }
选项的正确代码示例:
/*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": ["*"] }
选项的错误代码示例:
/*eslint no-warning-comments: ["error", { "decoration": ["*"] }]*/
//***** todo decorative asterisks are ignored *****//
/**
* TODO new lines and asterisks are also ignored in block comments.
*/
{ "decoration": ["/", "*"] }
选项的错误代码示例:
/*eslint no-warning-comments: ["error", { "decoration": ["/", "*"] }]*/
////// TODO decorative slashes and whitespace are ignored //////
//***** todo decorative asterisks are also ignored *****//
/**
* TODO new lines are also ignored in block comments.
*/
{ "decoration": ["/", "*"] }
选项的正确代码示例:
/*eslint no-warning-comments: ["error", { "decoration": ["/", "*"] }]*/
//!TODO preceded by non-decoration character
/**
*!TODO preceded by non-decoration character in a block comment
*/
# 何时不使用
- 如果您有一个大型代码库,而该代码库没有按照不使用此类警告术语的政策开发,您可能会收到数百个警告/错误,如果您无法修复所有这些警告/错误(例如,如果您不这样做,则可能会适得其反)没有时间去做)因为您可能会忽略其他警告/错误或习惯其中的许多并且不再关注它。
- 与上述相同的原因:您不应配置经常使用的术语(例如,您的评论中使用的母语的中心部分)。