Skip to content

vue/comment-directive

支持 <template> 中的注释指令

  • ⚙️ 此规则包含在 "plugin:vue/base"*.configs["flat/base"]"plugin:vue/vue2-essential"*.configs["flat/vue2-essential"]"plugin:vue/essential"*.configs["flat/essential"]"plugin:vue/vue2-strongly-recommended"*.configs["flat/vue2-strongly-recommended"]"plugin:vue/strongly-recommended"*.configs["flat/strongly-recommended"]"plugin:vue/vue2-recommended"*.configs["flat/vue2-recommended"]"plugin:vue/recommended"*.configs["flat/recommended"] 中。

此规则的唯一目的是在 <template> 和块级别提供 eslint-disable 功能。它支持使用以下注释:

¥Sole purpose of this rule is to provide eslint-disable functionality in the <template> and in the block level. It supports usage of the following comments:

  • eslint-disable

  • eslint-enable

  • eslint-disable-line

  • eslint-disable-next-line

注意

我们不能在标签中写 HTML 注释。

¥We can't write HTML comments in tags.

📖 规则详情

ESLint 不提供任何 API 来增强 eslint-disable 功能,并且 ESLint 规则不能影响其他规则。但 ESLint 提供 处理器 API

¥ESLint doesn't provide any API to enhance eslint-disable functionality and ESLint rules cannot affect other rules. But ESLint provides processors API.

此规则将所有 eslint-disable 类注释作为错误发送到 .vue 文件处理器的后处理,然后后处理删除所有 vue/comment-directive 错误和禁用区域中报告的错误。

¥This rule sends all eslint-disable-like comments as errors to the post-process of the .vue file processor, then the post-process removes all vue/comment-directive errors and the reported errors in disabled areas.

Now loading...

类似 eslint-disable 的注释可以在 <template> 和块级别中使用。

¥The eslint-disable-like comments can be used in the <template> and in the block level.

Now loading...

eslint-disable 注释在一个块之后无效。

¥The eslint-disable comments has no effect after one block.

Now loading...

类似 eslint-disable 的注释可以包含描述以解释注释的必要性。描述必须出现在指令之后,并且与指令之间由两个或更多连续的 - 字符分隔。例如:

¥The eslint-disable-like comments can include descriptions to explain why the comment is necessary. The description must occur after the directive and is separated from the directive by two or more consecutive - characters. For example:

Now loading...

🔧选项

¥🔧 Options

json
{
  "vue/comment-directive": ["error", {
    "reportUnusedDisableDirectives": false
  }]
}
  • reportUnusedDisableDirectives ...如果是 true,则报告未使用的 eslint-disable HTML 注释。默认 false

    ¥reportUnusedDisableDirectives ... If true, to report unused eslint-disable HTML comments. default false

{ "reportUnusedDisableDirectives": true }

Now loading...

注意

无法使用 eslint-disable HTML 注释抑制未使用的报告。

¥Unused reports cannot be suppressed with eslint-disable HTML comments.

📚扩展阅读

¥📚 Further Reading

🚀版本

¥🚀 Version

此规则在 eslint-plugin-vue v4.1.0 中引入

¥This rule was introduced in eslint-plugin-vue v4.1.0

🔍代码实现

¥🔍 Implementation

eslint-plugin-vue v10.0 中文网 - 粤ICP备13048890号