首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

no-warning-comments

开发人员经常会向未完成或需要审核的代码添加注释。在考虑代码准备就绪之前,最有可能您想修复或查看代码,然后删除注释。

代码语言:javascript
复制
// TODO: do something
// FIXME: this is not a good idea

规则细节

此规则报告包含其配置中指定的任何预定义术语的注释。

选项

This rule has an options object literal:

  • "terms":可选的术语数组。默认为["todo", "fixme", "xxx"]。术语匹配不区分大小写,并且作为整个词:fix匹配FIX但不匹配fixing。术语可以由多个词组成:really bad idea
  • "location":可选字符串,用于配置注释中检查匹配的位置。默认为"start"。其他值在评论中匹配anywhere

不正确代码的默认{ "terms": ["todo", "fixme", "xxx"], "location": "start" }选项示例:

代码语言:javascript
复制
/*eslint no-warning-comments: "error"*/

function callback(err, results) {
  if (err) {
    console.error(err);
    return;
  }
  // TODO
}

默认选项的正确代码示例{ "terms": ["todo", "fixme", "xxx"], "location": "start" }

代码语言:javascript
复制
/*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": ["todo", "fixme", "any other term"], "location": "anywhere" }选项代码示例:

代码语言:javascript
复制
/*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" }

代码语言:javascript
复制
/*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
 */

何时不使用它

  • 如果你有一个大型的代码库,如果你没有制定一个不使用这些警告条款的政策,那么你可能会得到数百个警告/错误,如果你无法修复所有这些警告/错误(例如,没有时间去做),因为你可能忽略了其他的警告/错误,或者习惯了其中的许多方法,并且不再关注它。
  • 与上述相同的原因:不应配置经常使用的术语(例如,评论中使用的本地语言的中心部分)。

版本

该规则在 ESLint 0.4.4中引入。

资源

扫码关注腾讯云开发者

领取腾讯云代金券