如果禁用未触发的规则,则抛出 eslint 错误

throwing an eslint error if disabling a rule that is not triggered

如果您在 line/file 中禁用不会触发错误的规则,是否有 eslint 规则可以抛出错误。

例如,如果在未使用控制台的文件中使用 /* eslint-disable no-console */ 会引发错误。

这样的规则已经存在了吗?我在 React 项目中大量使用 eslint,似乎这样的规则有很多实际用途。

基本 eslint 规则中没有这样做的规则。

您可以为自己创建一个或添加一个插件来添加此功能,例如:

eslint-plugin-eslint-comments

规则:https://github.com/mysticatea/eslint-plugin-eslint-comments/blob/master/docs/rules/no-unused-disable.md