可以在你的文件中使用以下格式的塊註釋來臨時禁止規則出現警告:
/* 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 */ 塊註釋放在文件頂部:
/* eslint-disable */
alert('foo');
你也可以對整個文件啓用或禁用警告:
/* eslint-disable no-alert */
// Disables no-alert for the rest of the file
alert('foo');
可以在你的文件中使用以下格式的行註釋在某一特定的行上禁用所有規則:
alert('foo');
// eslint-disable-line
// eslint-disable-next-linealert('foo');
在某一特定的行上禁用某個指定的規則:
alert('foo');
// eslint-disable-line no-alert
// eslint-disable-next-line no-alertalert('foo');
在某個特定的行上禁用多個規則:
alert('foo');
// eslint-disable-line no-alert, quotes, semi
// eslint-disable-next-line no-alert, quotes, semialert('foo');
上面的所有方法同樣適用於插件規則。例如,禁止eslint-plugin-example的 rule-name規則,把插件名(example)和規則名(rule-name)結合爲 example/rule-name:
foo(); // eslint-disable-line example/rule-name
注意:爲文件的某部分禁用警告的註釋,告訴 ESLint 不要對禁用的代碼報告規則的衝突。ESLint 仍解析整個文件,然而,禁用的代碼仍需要是有效的 JavaScript 語法。