为了在JSHint中关闭特定行的linting规则,我们使用以下规则:
/* jshint ignore:start*/
$scope.someVar = ConstructorFunction();
/* jshint ignore:end */
我一直在尝试为eslint找到与上述内容相同的内容。
为了在JSHint中关闭特定行的linting规则,我们使用以下规则:
/* jshint ignore:start*/
$scope.someVar = ConstructorFunction();
/* jshint ignore:end */
我一直在尝试为eslint找到与上述内容相同的内容。
当前回答
要对以下文件的其余部分禁用单个规则:
/* eslint no-undef: "off"*/
const uploadData = new FormData();
其他回答
答复
您可以使用内联注释://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-禁用带有内联注释的规则
您还可以通过在启用(打开)和禁用(关闭)块中指定特定规则(而不是全部)来禁用特定规则:
/* 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-规则
要禁用特定行上的所有规则,请执行以下操作:
alert('foo'); // eslint-disable-line
从配置ESLint-使用内联注释禁用规则:
/* eslint-disable no-alert, no-console */
/* eslint-disable */
alert('foo');
/* eslint-enable */
/* eslint-disable no-alert, no-console */
alert('foo');
console.log('bar');
/* eslint-enable no-alert, no-console */
/* eslint-disable */
alert('foo');
/* eslint-disable no-alert */
alert('foo');
alert('foo'); // eslint-disable-line
// eslint-disable-next-line
alert('foo');
alert('foo'); // eslint-disable-line no-alert
// eslint-disable-next-line no-alert
alert('foo');
alert('foo'); // eslint-disable-line no-alert, quotes, semi
// eslint-disable-next-line no-alert, quotes, semi
alert('foo');
foo(); // eslint-disable-line example/rule-name
我的回答与其他人的回答相似,但表明了你如何也可以在同一行给自己添加评论。
// 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!)