是否可以关闭整个文件的eslint规则?例如:
// eslint-disable-file no-use-before-define
(类似于eslint-disable-line。)我经常遇到这样的情况,在某个文件中,我在许多地方违反了特定的规则,这对该文件来说是OK的,但我不想为整个项目禁用该规则,也不想为该特定文件禁用其他规则。
是否可以关闭整个文件的eslint规则?例如:
// eslint-disable-file no-use-before-define
(类似于eslint-disable-line。)我经常遇到这样的情况,在某个文件中,我在许多地方违反了特定的规则,这对该文件来说是OK的,但我不想为整个项目禁用该规则,也不想为该特定文件禁用其他规则。
当前回答
你可以配置eslint overrides属性来关闭匹配glob模式的文件的特定规则,如下所示。
在这里,我想关闭测试所有文件的no-duplicate-string规则。
overrides: [
{
files: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
rules: {
'sonarjs/no-duplicate-string': 'off'
}
}
]
其他回答
/* eslint-disable */
//suppress all warnings between comments
alert('foo');
/* eslint-enable */
这将禁用块内的所有eslint规则。
你可以通过在项目的根目录中创建一个.eslintignore文件来告诉ESLint忽略特定的文件和目录:
eslintignore。
build/*.js
config/*.js
bower_components/foo/*.js
ignore模式的行为符合.gitignore规范。 (不要忘记重新启动编辑器。)
例如,你可以把这个放在文件的顶部:
/* eslint-disable no-console */
你可以使用/*eslint [<rule: "off"], >]*/关闭一个文件的特定规则
/* eslint no-console: "off", no-mixed-operators: "off" */
版本:eslint@4.3.0
接受的答案不适合我(可能是eslint的不同版本…?)我使用eslint v3.19.0),但确实找到了一个解决方案与以下…
将以下内容放在文件顶部
/* eslint-disable - no-use-before-define */
这将禁用整个文件的规则