为了在JSHint中关闭特定行的linting规则,我们使用以下规则:

/* jshint ignore:start*/
$scope.someVar = ConstructorFunction();
/* jshint ignore:end */

我一直在尝试为eslint找到与上述内容相同的内容。


当前回答

您还可以通过在启用(打开)和禁用(关闭)块中指定特定规则(而不是全部)来禁用特定规则:

/* eslint-disable no-alert, no-console */

alert('foo');
console.log('bar');

/* eslint-enable no-alert */

通过上面@gobballMagic的链接:http://eslint.org/docs/user-guide/configuring.html#configuring-规则

其他回答

答复

您可以使用内联注释://eslint disable next line rule name。

实例

// eslint-disable-next-line no-console
console.log('eslint will ignore the no-console on this line of code');

参考

ESLint-禁用带有内联注释的规则

您可以在项目中添加给.eslitingnore文件带来错误的文件。与所有.vue文件一样,只需添加/*.vue

我的回答与其他人的回答相似,但表明了你如何也可以在同一行给自己添加评论。

// eslint-disable-line // THIS WON"T WORK

使用--如果您还需要在该行上写注释(例如,可能是esint被禁用的原因)

// eslint-disable-line -- comment to self (This DOES work)

可与特定eslint规则一起使用以忽略:

// eslint-disable-line no-console -- comment to self (This Also Works!)

您还可以通过在启用(打开)和禁用(关闭)块中指定特定规则(而不是全部)来禁用特定规则:

/* eslint-disable no-alert, no-console */

alert('foo');
console.log('bar');

/* eslint-enable no-alert */

通过上面@gobballMagic的链接:http://eslint.org/docs/user-guide/configuring.html#configuring-规则

单行注释在反作用哑功能组件中对我不起作用,我通过添加/*eslint禁用insertEslintErrorDefinition此处*/

(通常,如果您正在使用vs代码并得到eslint错误,您可以单击给出错误的行,一个灯泡将显示在vs代码中,右键单击灯泡并选择任何禁用选项,vs代码将为您执行此操作。)