[英]Eslint: disable all rules except 1 rule?
I want to use Eslint to check the output of my minifier.我想用 Eslint 检查我的 minifier 的 output。 Obviously, this would trigger a lot of errors.
显然,这会引发很多错误。 I'm only interested in a single rule (
compat/compat
).我只对单个规则 (
compat/compat
) 感兴趣。 How can I disable all the other ones?我怎样才能禁用所有其他的?
Edit:编辑:
Here's my .eslintrc.js
:这是我的
.eslintrc.js
:
module.exports = {
extends: ['plugin:compat/recommended'],
env: {
browser: true,
},
};
Edit:编辑:
I found the reset
option in the docs, but it seems to be disabled for my installation:我在文档中找到了
reset
选项,但它似乎在我的安装中被禁用:
$ npx eslint file.js --config .eslintrc.browserslist.js --quiet --reset
Invalid option '--reset' - perhaps you meant '--ext'?
$ npx eslint --version
v6.8.0
$ npx eslint -h
eslint [options] file.js [file.js] [dir]
Basic configuration:
--no-eslintrc Disable use of configuration from .eslintrc.*
-c, --config path::String Use this configuration, overriding .eslintrc.* config options if present
--env [String] Specify environments
--ext [String] Specify JavaScript file extensions - default: .js
--global [String] Define global variables
--parser String Specify the parser to be used
--parser-options Object Specify parser options
--resolve-plugins-relative-to path::String A folder where plugins should be resolved from, CWD by default
Specifying rules and plugins:
--rulesdir [path::String] Use additional rules from this directory
--plugin [String] Specify plugins
--rule Object Specify rules
Fixing problems:
--fix Automatically fix problems
--fix-dry-run Automatically fix problems without saving the changes to the file system
--fix-type Array Specify the types of fixes to apply (problem, suggestion, layout)
Ignoring files:
--ignore-path path::String Specify path of ignore file
--no-ignore Disable use of ignore files and patterns
--ignore-pattern [String] Pattern of files to ignore (in addition to those in .eslintignore)
Using stdin:
--stdin Lint code provided on <STDIN> - default: false
--stdin-filename String Specify filename to process STDIN as
Handling warnings:
--quiet Report errors only - default: false
--max-warnings Int Number of warnings to trigger nonzero exit code - default: -1
Output:
-o, --output-file path::String Specify file to write report to
-f, --format String Use a specific output format - default: stylish
--color, --no-color Force enabling/disabling of color
Inline configuration comments:
--no-inline-config Prevent comments from changing config or rules
--report-unused-disable-directives Adds reported errors for unused eslint-disable directives
Caching:
--cache Only check changed files - default: false
--cache-file path::String Path to the cache file. Deprecated: use --cache-location - default: .eslintcache
--cache-location path::String Path to the cache file or directory
Miscellaneous:
--init Run config initialization wizard - default: false
--env-info Output execution environment information - default: false
--no-error-on-unmatched-pattern Prevent errors when pattern is unmatched
--debug Output debugging information
-h, --help Show help
-v, --version Output the version number
--print-config path::String Print the configuration for the given file
If you want to use your.eslintrc file to keep your configuration (parser, plugin settings, etc), you can use eslint-nibble with the --rule=compat/compat
flag.如果你想使用你的 .eslintrc 文件来保留你的配置(解析器、插件设置等),你可以使用带有
--rule=compat/compat
标志的eslint- nibble。 This will respect your normal configuration, but only show you errors from that one rule.这将尊重您的正常配置,但只会向您显示该规则的错误。
Disclaimer: I'm the creator of eslint-nibble.免责声明:我是 eslint-nibble 的创建者。
Simply specify the rule you want to use in your ESLint config, for instance this would enable only the "semi" rule:只需在 ESLint 配置中指定要使用的规则,例如这将仅启用“半”规则:
module.exports = {
"rules": {
"semi": ["error", "always"],
}
};
https://eslint.org/docs/user-guide/configuring#configuring-rules https://eslint.org/docs/user-guide/configuring#configuring-rules
Or you could specify it with the --rule flag或者您可以使用 --rule 标志指定它
You can add root: true
to the config file, that way it will not inherit the other config files.您可以将
root: true
添加到配置文件中,这样它就不会继承其他配置文件。 The eslint.json
file should look like this: eslint.json
文件应如下所示:
module.exports = {
root: true,
rules: {
semi: ["error", "always"],
}
};
Eslint's parser options currently default to ecmaVersion: 5
[1]. Eslint 的解析器选项当前默认为
ecmaVersion: 5
[1]。 So in case, your code is using ECMAScript > 5, eslint will start enforcing the rules of ECMAScript 5, 6, and so on.因此,如果您的代码使用 ECMAScript > 5,eslint 将开始强制执行 ECMAScript 5、6 等规则。 Hence, apart from defining
root: true
, it's important finding the right ecmaVersion
.因此,除了定义
root: true
,重要的是找到正确的ecmaVersion
。 An ideal eslint config for projects beyond ECMAScript 5 that has all eslint rules disabled looks as follows:对于 ECMAScript 5 以外的项目,禁用所有 eslint 规则的理想 eslint 配置如下所示:
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 9
},
rules: {}
};
Where parserOptions.ecmaVersion
is tuned to the code base's ECMAScript version.其中
parserOptions.ecmaVersion
被调整到代码库的 ECMAScript 版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.