本文翻译自:Turning off eslint rule for a specific line
In order to turn off linting rule for a particular line in JSHint we use the following rule: 为了关闭JSHint中特定行的linting规则,我们使用以下规则:
/* jshint ignore:start*/
$scope.someVar = ConstructorFunction();
/* jshint ignore:end */
I have been trying to locate the equivalent of the above for eslint. 我一直试图找到相当于以上的eslint。
参考:https://stackoom.com/question/1sMPh/关闭特定行的eslint规则
You can use the following 您可以使用以下内容
/*eslint-disable */
//suppress all warnings between comments
alert('foo');
/*eslint-enable */
Which is slightly buried the "configuring rules" section of the docs ; 这稍微掩盖了文档的“配置规则”部分;
To disable a warning for an entire file, you can include a comment at the top of the file eg 要禁用整个文件的警告,您可以在文件顶部添加注释,例如
/*eslint eqeqeq:0*/
ESlint has now been updated with a better way disable a single line, see @goofballLogic's excellent answer . ESlint现在已经更新了更好的禁用单行的方法,请参阅@ goofballLogic的优秀答案 。
You can use the single line syntax now: 您现在可以使用单行语法:
var thing = new Thing(); // eslint-disable-line no-use-before-define
thing.sayHello();
function Thing() {
this.sayHello = function() { console.log("hello"); };
}
Or if you don't want to have a comment on the same line with the actual code, it is possible to disable next line: 或者,如果您不想在实际代码的同一行上发表评论,则可以禁用下一行:
// eslint-disable-next-line no-use-before-define
var thing = new Thing();
Requested docs link: http://eslint.org/docs/user-guide/configuring.html#configuring-rules 请求的文档链接: http : //eslint.org/docs/user-guide/configuring.html#configuring-rules
You can also disable a specific rule/rules (rather than all) by specifying them in the enable (open) and disable (close) blocks: 您还可以通过在启用(打开)和禁用(关闭)块中指定特定规则/规则 (而不是全部)来禁用它们:
/* eslint-disable no-alert, no-console */
alert('foo');
console.log('bar');
/* eslint-enable no-alert */
via @goofballMagic's link above: http://eslint.org/docs/user-guide/configuring.html#configuring-rules via @ goofballMagic上面的链接: http ://eslint.org/docs/user-guide/configuring.html#configuring-rules
The general end of line comment, // eslint-disable-line
, does not need anything after it: no need to look up a code to specify what you wish ES Lint to ignore. 行尾注释// eslint-disable-line
的一般结束后不需要任何内容:无需查找代码来指定您希望ES Lint忽略的内容。
If you need to have any syntax ignored for any reason other than a quick debugging, you have problems: why not update your delint config? 如果除了快速调试之外由于任何原因需要忽略任何语法,则会遇到问题:为什么不更新delint配置?
I enjoy // eslint-disable-line
to allow me to insert console
for a quick inspection of a service, without my development environment holding me back because of the breach of protocol. 我喜欢// eslint-disable-line
允许我插入console
以快速检查服务,而我的开发环境却因为违反协议而阻止我。 (I generally ban console
, and use a logging class - which sometimes builds upon console
.) (我通常禁止console
,并使用日志类 - 有时建立在console
。)
You can use an inline comment: // eslint-disable-next-line rule-name
. 您可以使用内联注释: // 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 - Disabling Rules with Inline Comments ESLint - 使用内联注释禁用规则