命令行接口参考
ESLint 命令行接口(CLI)允许你从终端执行代码检查。CLI 有多种选项,你可以传入这些选项来配置 ESLint。
🌐 The ESLint Command Line Interface (CLI) lets you execute linting from the terminal. The CLI has a variety of options that you can pass to configure ESLint.
运行 CLI
🌐 Run the CLI
ESLint 的安装需要 Node.js。请按照 入门指南 中的说明来安装 ESLint。
🌐 ESLint requires Node.js for installation. Follow the instructions in the Getting Started Guide to install ESLint.
大多数用户使用 npx 在命令行上运行 ESLint,如下所示:
🌐 Most users use npx to run ESLint on the command line like this:
npm
npx eslint [options] [file|dir|glob]*
yarn
yarn dlx eslint [options] [file|dir|glob]*
pnpm
pnpm dlx eslint [options] [file|dir|glob]*
bun
bunx eslint [options] [file|dir|glob]*
如:
🌐 Such as:
npm
# Run on two files
npx eslint file1.js file2.js
yarn
# Run on two files
yarn dlx eslint file1.js file2.js
pnpm
# Run on two files
pnpm dlx eslint file1.js file2.js
bun
# Run on two files
bunx eslint file1.js file2.js
or
npm
# Run on multiple files
npx eslint lib/**
yarn
# Run on multiple files
yarn dlx eslint lib/**
pnpm
# Run on multiple files
pnpm dlx eslint lib/**
bun
# Run on multiple files
bunx eslint lib/**
请注意,当将全局模式作为参数传递时,它会被你的 shell 展开。展开的结果可能会根据你的 shell 及其配置而有所不同。如果你想使用节点 glob 语法,则必须对参数加引号(如果需要在 Windows 上运行,则使用双引号),如下所示:
🌐 Please note that when passing a glob as a parameter, it is expanded by your shell. The results of the expansion can vary depending on your shell, and its configuration. If you want to use node glob syntax, you have to quote your parameter (using double quotes if you need it to run in Windows), as follows:
npm
npx eslint "lib/**"
yarn
yarn dlx eslint "lib/**"
pnpm
pnpm dlx eslint "lib/**"
bun
bunx eslint "lib/**"
你也可以省略文件参数,ESLint 将使用 .。例如,这两行执行相同的操作:
🌐 You can also omit the file arguments and ESLint will use .. For instance, these two lines perform the same operation:
npm
npx eslint .
yarn
yarn dlx eslint .
pnpm
pnpm dlx eslint .
bun
bunx eslint .
npm
npx eslint
yarn
yarn dlx eslint
pnpm
pnpm dlx eslint
bun
bunx eslint
注意: 你也可以使用其他包管理器,例如 Yarn 或 pnpm 来运行 ESLint。对于 pnpm 使用 pnpm dlx eslint,对于 Yarn 使用 yarn dlx eslint。
将多个值传递给一个选项
🌐 Pass Multiple Values to an Option
可以通过重复选项或使用逗号分隔的列表来指定接受多个值的选项(除 --ignore-pattern 外,后者不允许使用第二种方式)。
🌐 Options that accept multiple values can be specified by repeating the option or with a comma-delimited list (other than --ignore-pattern, which does not allow the second style).
接受多个值的选项示例:
🌐 Examples of options that accept multiple values:
npm
npx eslint --global describe --global it tests/
yarn
yarn dlx eslint --global describe --global it tests/
pnpm
pnpm dlx eslint --global describe --global it tests/
bun
bunx eslint --global describe --global it tests/
或
🌐 OR
npm
npx eslint --global describe,it tests/
yarn
yarn dlx eslint --global describe,it tests/
pnpm
pnpm dlx eslint --global describe,it tests/
bun
bunx eslint --global describe,it tests/
选项
🌐 Options
你可以通过运行 npx eslint -h 来查看所有 CLI 选项。
🌐 You can view all the CLI options by running npx eslint -h.
eslint [options] file.js [file.js] [dir]
Basic configuration:
--no-config-lookup Disable look up for eslint.config.js
-c, --config path::String Use this configuration instead of eslint.config.js, eslint.config.mjs, or eslint.config.cjs
--inspect-config Open the config inspector with the current configuration
--ext [String] Specify additional file extensions to lint
--global [String] Define global variables
--parser String Specify the parser to be used
--parser-options Object Specify parser options
Specify Rules and Plugins:
--plugin [String] Specify plugins
--rule Object Specify rules
Fix 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 (directive, problem, suggestion, layout)
Ignore Files:
--no-ignore Disable use of ignore files and patterns
--ignore-pattern [String] Patterns of files to ignore
Use stdin:
--stdin Lint code provided on <STDIN> - default: false
--stdin-filename String Specify filename to process STDIN as
Handle 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 and eslint-enable directives
--report-unused-disable-directives-severity String Chooses severity level for reporting unused eslint-disable and eslint-enable directives - either: off, warn, error, 0, 1, or 2
--report-unused-inline-configs String Adds reported errors for unused eslint inline config comments - either: off, warn, error, 0, 1, or 2
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
--cache-strategy String Strategy to use for detecting changed files in the cache - either: metadata or content - default: metadata
Suppressing Violations:
--suppress-all Suppress all violations - default: false
--suppress-rule [String] Suppress specific rules
--suppressions-location path::String Specify the location of the suppressions file
--prune-suppressions Prune unused suppressions - default: false
--pass-on-unpruned-suppressions Ignore unused suppressions - default: false
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
--exit-on-fatal-error Exit with exit code 2 in case of fatal error - default: false
--no-warn-ignored Suppress warnings when the file list includes ignored files
--pass-on-no-patterns Exit with exit code 0 in case no file patterns are passed
--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
--stats Add statistics to the lint report - default: false
--flag [String] Enable a feature flag
--mcp Start the ESLint MCP server
--concurrency Int|String Number of linting threads, auto to choose automatically, off for no multithreading - default: off
基本配置
🌐 Basic Configuration
--no-config-lookup
禁用从文件中使用配置。
🌐 Disables use of configuration from files.
- 参数类型:无参数。
--no-config-lookup 示例
🌐 --no-config-lookup example
npm
npx eslint --no-config-lookup file.js
yarn
yarn dlx eslint --no-config-lookup file.js
pnpm
pnpm dlx eslint --no-config-lookup file.js
bun
bunx eslint --no-config-lookup file.js
-c,--config
🌐 -c, --config
此选项允许你为 ESLint 指定一个额外的配置文件(更多信息请参见 配置 ESLint)。
🌐 This option allows you to specify an additional configuration file for ESLint (see Configure ESLint for more).
- 参数类型:字符串。文件路径。
- 多个参数:无
-c,--config 示例
🌐 -c, --config example
npm
npx eslint -c ~/my.eslint.config.js file.js
yarn
yarn dlx eslint -c ~/my.eslint.config.js file.js
pnpm
pnpm dlx eslint -c ~/my.eslint.config.js file.js
bun
bunx eslint -c ~/my.eslint.config.js file.js
此示例使用位于 ~/my.eslint.config.js 的配置文件,它用于代替搜索 eslint.config.js 文件。
🌐 This example uses the configuration file at ~/my.eslint.config.js, which is used instead of searching for an eslint.config.js file.
--inspect-config
此选项运行 npx @eslint/config-inspector@latest 来启动 配置检查器。你可以使用配置检查器更好地理解你的配置在做什么以及它适用于哪些文件。当你使用此标志时,CLI 不会执行 lint 检查。
🌐 This option runs npx @eslint/config-inspector@latest to start the config inspector. You can use the config inspector to better understand what your configuration is doing and which files it applies to. When you use this flag, the CLI does not perform linting.
- 参数类型:无参数。
--inspect-config 示例
🌐 --inspect-config example
npm
npx eslint --inspect-config
yarn
yarn dlx eslint --inspect-config
pnpm
pnpm dlx eslint --inspect-config
bun
bunx eslint --inspect-config
--ext
此选项允许你指定要 lint 的其他文件扩展名。
🌐 This option allows you to specify additional file extensions to lint.
- 参数类型:字符串。文件扩展名。
- 多个参数:是
- 默认值:默认情况下,ESLint 会检查扩展名为
.js、.mjs、.cjs的文件,以及配置文件中指定的其他扩展名 的文件。
此选项主要用于与 --no-config-lookup 选项结合使用,因为在这种情况下没有配置文件可以指定额外的扩展。
🌐 This option is primarily intended for use in combination with the --no-config-lookup option, since in that case there is no configuration file in which the additional extensions would be specified.
--ext 示例
🌐 --ext example
npm
# Include .ts files
npx eslint . --ext .ts
yarn
# Include .ts files
yarn dlx eslint . --ext .ts
pnpm
# Include .ts files
pnpm dlx eslint . --ext .ts
bun
# Include .ts files
bunx eslint . --ext .ts
npm
# Include .ts and .tsx files
npx eslint . --ext .ts --ext .tsx
yarn
# Include .ts and .tsx files
yarn dlx eslint . --ext .ts --ext .tsx
pnpm
# Include .ts and .tsx files
pnpm dlx eslint . --ext .ts --ext .tsx
bun
# Include .ts and .tsx files
bunx eslint . --ext .ts --ext .tsx
npm
# Also include .ts and .tsx files
npx eslint . --ext .ts,.tsx
yarn
# Also include .ts and .tsx files
yarn dlx eslint . --ext .ts,.tsx
pnpm
# Also include .ts and .tsx files
pnpm dlx eslint . --ext .ts,.tsx
bun
# Also include .ts and .tsx files
bunx eslint . --ext .ts,.tsx
--global
此选项定义全局变量,以便它们不会被 no-undef 规则标记为未定义。
🌐 This option defines global variables so that they are not flagged as undefined by the no-undef rule.
- 参数类型:字符串。全局变量的名称。任何指定的全局变量默认被假定为只读,但在变量名后附加
:true可以确保no-undef也允许写入。 - 多个参数:是
--global 示例
🌐 --global example
npm
npx eslint --global require,exports:true file.js
yarn
yarn dlx eslint --global require,exports:true file.js
pnpm
pnpm dlx eslint --global require,exports:true file.js
bun
bunx eslint --global require,exports:true file.js
npm
npx eslint --global require --global exports:true
yarn
yarn dlx eslint --global require --global exports:true
pnpm
pnpm dlx eslint --global require --global exports:true
bun
bunx eslint --global require --global exports:true
--parser
此选项允许你指定 ESLint 使用的解析器。
🌐 This option allows you to specify a parser to be used by ESLint.
- 参数类型:字符串。由 ESLint 使用的解析器。
- 多个参数:无
- 默认值:
espree
--parser 示例
🌐 --parser example
npm
# Use TypeScript ESLint parser
npx eslint --parser @typescript-eslint/parser file.ts
yarn
# Use TypeScript ESLint parser
yarn dlx eslint --parser @typescript-eslint/parser file.ts
pnpm
# Use TypeScript ESLint parser
pnpm dlx eslint --parser @typescript-eslint/parser file.ts
bun
# Use TypeScript ESLint parser
bunx eslint --parser @typescript-eslint/parser file.ts
--parser-options
此选项允许你指定由 ESLint 使用的解析器选项。可用的解析器选项取决于所使用的解析器。
🌐 This option allows you to specify parser options to be used by ESLint. The available parser options are determined by the parser being used.
- 参数类型:用冒号分隔的键/值对 (
:)。 - 多个参数:是
--parser-options 示例
🌐 --parser-options example
npm
# fails with a parsing error
echo '3 ** 4' | npx eslint --stdin --parser-options ecmaVersion:6
yarn
# fails with a parsing error
echo '3 ** 4' | yarn dlx eslint --stdin --parser-options ecmaVersion:6
pnpm
# fails with a parsing error
echo '3 ** 4' | pnpm dlx eslint --stdin --parser-options ecmaVersion:6
bun
# fails with a parsing error
echo '3 ** 4' | bunx eslint --stdin --parser-options ecmaVersion:6
npm
# succeeds, yay!
echo '3 ** 4' | npx eslint --stdin --parser-options ecmaVersion:7
yarn
# succeeds, yay!
echo '3 ** 4' | yarn dlx eslint --stdin --parser-options ecmaVersion:7
pnpm
# succeeds, yay!
echo '3 ** 4' | pnpm dlx eslint --stdin --parser-options ecmaVersion:7
bun
# succeeds, yay!
echo '3 ** 4' | bunx eslint --stdin --parser-options ecmaVersion:7
指定规则和插件
🌐 Specify Rules and Plugins
--plugin
此选项指定要加载的插件。
🌐 This option specifies a plugin to load.
- 参数类型:字符串。插件名称。你可以选择省略插件名称中的前缀
eslint-plugin-。 - 多个参数:是
在使用插件之前,你必须使用 npm 安装它。
🌐 Before using the plugin, you have to install it using npm.
--plugin 示例
🌐 --plugin example
npm
npx eslint --plugin jquery file.js
yarn
yarn dlx eslint --plugin jquery file.js
pnpm
pnpm dlx eslint --plugin jquery file.js
bun
bunx eslint --plugin jquery file.js
npm
npx eslint --plugin eslint-plugin-mocha file.js
yarn
yarn dlx eslint --plugin eslint-plugin-mocha file.js
pnpm
pnpm dlx eslint --plugin eslint-plugin-mocha file.js
bun
bunx eslint --plugin eslint-plugin-mocha file.js
--rule
此选项指定要使用的规则。
🌐 This option specifies the rules to be used.
- 参数类型:使用 levn 格式指定的规则及其配置。
- 多个参数:是
这些规则会与配置文件中指定的任何规则合并。如果规则在插件中定义,则必须在规则 ID 前加上插件名称和 /。
🌐 These rules are merged with any rules specified with configuration files. If the rule is defined in a plugin, you have to prefix the rule ID with the plugin name and a /.
要忽略配置文件中的规则,仅运行命令行中指定的规则,请将 --rule 标志与 --no-config-lookup 标志结合使用。
🌐 To ignore rules in configuration files and only run rules specified in the command line, use the --rule flag in combination with the --no-config-lookup flag.
--rule 示例
🌐 --rule example
npm
# Apply single rule
npx eslint --rule 'quotes: [error, double]'
yarn
# Apply single rule
yarn dlx eslint --rule 'quotes: [error, double]'
pnpm
# Apply single rule
pnpm dlx eslint --rule 'quotes: [error, double]'
bun
# Apply single rule
bunx eslint --rule 'quotes: [error, double]'
npm
# Apply multiple rules
npx eslint --rule 'guard-for-in: error' --rule 'brace-style: [error, 1tbs]'
yarn
# Apply multiple rules
yarn dlx eslint --rule 'guard-for-in: error' --rule 'brace-style: [error, 1tbs]'
pnpm
# Apply multiple rules
pnpm dlx eslint --rule 'guard-for-in: error' --rule 'brace-style: [error, 1tbs]'
bun
# Apply multiple rules
bunx eslint --rule 'guard-for-in: error' --rule 'brace-style: [error, 1tbs]'
npm
# Apply rule from jquery plugin
npx eslint --rule 'jquery/dollar-sign: error'
yarn
# Apply rule from jquery plugin
yarn dlx eslint --rule 'jquery/dollar-sign: error'
pnpm
# Apply rule from jquery plugin
pnpm dlx eslint --rule 'jquery/dollar-sign: error'
bun
# Apply rule from jquery plugin
bunx eslint --rule 'jquery/dollar-sign: error'
npm
# Only apply rule from the command line
npx eslint --rule 'quotes: [error, double]' --no-config-lookup
yarn
# Only apply rule from the command line
yarn dlx eslint --rule 'quotes: [error, double]' --no-config-lookup
pnpm
# Only apply rule from the command line
pnpm dlx eslint --rule 'quotes: [error, double]' --no-config-lookup
bun
# Only apply rule from the command line
bunx eslint --rule 'quotes: [error, double]' --no-config-lookup
修复问题
🌐 Fix Problems
--fix
此选项指示 ESLint 尽可能多地 修复 问题。修复操作会直接作用于实际文件,只有剩下未修复的问题会被输出。
🌐 This option instructs ESLint to try to fix as many issues as possible. The fixes are made to the actual files themselves and only the remaining unfixed issues are output.
- 参数类型:无参数。
并非所有问题都可以使用此选项解决,并且该选项在以下情况下不起作用:
🌐 Not all problems are fixable using this option, and the option does not work in these situations:
- 当代码通过管道传输到 ESLint 时,此选项会引发错误。
- 此选项对使用处理器的代码没有影响,除非处理器选择允许自动修复。
如果你想从 stdin 修复代码,或者想在不实际写入文件的情况下获取修复内容,请使用 --fix-dry-run 选项。
🌐 If you want to fix code from stdin or otherwise want to get the fixes without actually writing them to the file, use the --fix-dry-run option.
--fix 示例
🌐 --fix example
npm
npx eslint --fix file.js
yarn
yarn dlx eslint --fix file.js
pnpm
pnpm dlx eslint --fix file.js
bun
bunx eslint --fix file.js
--fix-dry-run
此选项的效果与 --fix 相同,只是修复不会保存到文件系统中。因为默认的格式化工具不会输出已修复的代码,所以你需要使用其他格式化工具(例如 --format json)来获取修复内容。
🌐 This option has the same effect as --fix with the difference that the fixes are not saved to the file system. Because the default formatter does not output the fixed code, you’ll have to use another formatter (e.g. --format json) to get the fixes.
- 参数类型:无参数。
这使得在与 --stdin 标志一起使用时,有可能修复 stdin 的代码。
🌐 This makes it possible to fix code from stdin when used with the --stdin flag.
此标志对于需要从命令行自动修复文本而不将其保存到文件系统的集成(例如编辑器插件)很有用。
🌐 This flag can be useful for integrations (e.g. editor plugins) which need to autofix text from the command line without saving it to the filesystem.
--fix-dry-run 示例
🌐 --fix-dry-run example
npm
getSomeText | npx eslint --stdin --fix-dry-run --format json
yarn
getSomeText | yarn dlx eslint --stdin --fix-dry-run --format json
pnpm
getSomeText | pnpm dlx eslint --stdin --fix-dry-run --format json
bun
getSomeText | bunx eslint --stdin --fix-dry-run --format json
--fix-type
此选项允许你指定在使用 --fix 或 --fix-dry-run 时要应用的修复类型。
🌐 This option allows you to specify the type of fixes to apply when using either --fix or --fix-dry-run.
- 参数类型:字符串。以下修复类型之一:
problem- 修复代码中的潜在错误suggestion- 将修复应用于改进它的代码layout- 应用不改变程序结构 (AST) 的修复directive- 对内联指令如// eslint-disable应用修复
- 多个参数:是
如果你正在使用另一个程序来格式化代码,但你仍然希望 ESLint 应用其他类型的修复,则此选项很有用。
🌐 This option is helpful if you are using another program to format your code, but you would still like ESLint to apply other types of fixes.
--fix-type 示例
🌐 --fix-type example
npm
npx eslint --fix --fix-type suggestion .
yarn
yarn dlx eslint --fix --fix-type suggestion .
pnpm
pnpm dlx eslint --fix --fix-type suggestion .
bun
bunx eslint --fix --fix-type suggestion .
npm
npx eslint --fix --fix-type suggestion --fix-type problem .
yarn
yarn dlx eslint --fix --fix-type suggestion --fix-type problem .
pnpm
pnpm dlx eslint --fix --fix-type suggestion --fix-type problem .
bun
bunx eslint --fix --fix-type suggestion --fix-type problem .
npm
npx eslint --fix --fix-type suggestion,layout .
yarn
yarn dlx eslint --fix --fix-type suggestion,layout .
pnpm
pnpm dlx eslint --fix --fix-type suggestion,layout .
bun
bunx eslint --fix --fix-type suggestion,layout .
忽略文件
🌐 Ignore Files
--no-ignore
禁用从 --ignore-pattern 标志和配置中的 ignores 属性排除文件。
🌐 Disables excluding of files from --ignore-pattern flags and the ignores property in configuration.
- 参数类型:无参数。
--no-ignore 示例
🌐 --no-ignore example
npm
npx eslint --no-ignore file.js
yarn
yarn dlx eslint --no-ignore file.js
pnpm
pnpm dlx eslint --no-ignore file.js
bun
bunx eslint --no-ignore file.js
--ignore-pattern
此选项允许你指定要忽略的文件模式。
🌐 This option allows you to specify patterns of files to ignore.
- 参数类型:字符串。支持的语法与
ignores模式 相同,这些模式使用 minimatch 语法。你应该将模式加上引号,以避免 shell 对通配符模式的解释。 - 多个参数:是
--ignore-pattern 示例
🌐 --ignore-pattern example
npm
npx eslint --ignore-pattern "/lib/" --ignore-pattern "/src/vendor/*" .
yarn
yarn dlx eslint --ignore-pattern "/lib/" --ignore-pattern "/src/vendor/*" .
pnpm
pnpm dlx eslint --ignore-pattern "/lib/" --ignore-pattern "/src/vendor/*" .
bun
bunx eslint --ignore-pattern "/lib/" --ignore-pattern "/src/vendor/*" .
使用标准输入
🌐 Use stdin
--stdin
此选项指示 ESLint 从 STDIN 而不是从文件读取并检查源代码。你可以使用它将代码通过管道传给 ESLint。
🌐 This option tells ESLint to read and lint source code from STDIN instead of from files. You can use this to pipe code to ESLint.
- 参数类型:无参数。
--stdin 示例
🌐 --stdin example
npm
cat myFile.js | npx eslint --stdin
yarn
cat myFile.js | yarn dlx eslint --stdin
pnpm
cat myFile.js | pnpm dlx eslint --stdin
bun
cat myFile.js | bunx eslint --stdin
--stdin-filename
此选项允许你指定一个文件名来处理 STDIN。
🌐 This option allows you to specify a filename to process STDIN as.
- 参数类型:字符串。文件路径。
- 多个参数:无
这在处理来自 STDIN 的文件并且你有依赖于文件名的规则时很有用。
🌐 This is useful when processing files from STDIN and you have rules which depend on the filename.
--stdin-filename 示例
🌐 --stdin-filename example
npm
cat myFile.js | npx eslint --stdin --stdin-filename myfile.js
yarn
cat myFile.js | yarn dlx eslint --stdin --stdin-filename myfile.js
pnpm
cat myFile.js | pnpm dlx eslint --stdin --stdin-filename myfile.js
bun
cat myFile.js | bunx eslint --stdin --stdin-filename myfile.js
处理警告
🌐 Handle Warnings
--quiet
此选项允许你禁用对警告的报告以及执行设置为警告的规则。如果启用此选项,ESLint 将仅报告错误,并且只会运行设置为错误的规则。
🌐 This option allows you to disable reporting on warnings and running of rules set to warn. If you enable this option, only errors are reported by ESLint and only rules set to error will be run.
- 参数类型:无参数。
--quiet 示例
🌐 --quiet example
npm
npx eslint --quiet file.js
yarn
yarn dlx eslint --quiet file.js
pnpm
pnpm dlx eslint --quiet file.js
bun
bunx eslint --quiet file.js
--max-warnings
此选项允许你指定警告阈值,如果你的项目中有太多警告级别的规则违规,可用于强制 ESLint 以错误状态退出。
🌐 This option allows you to specify a warning threshold, which can be used to force ESLint to exit with an error status if there are too many warning-level rule violations in your project.
- 参数类型:整数。允许的最大警告次数。要防止此行为,请不要使用此选项或将参数指定为
-1。 - 多个参数:无
通常,如果 ESLint 运行时没有发现错误(只有警告),它会以成功退出状态退出。然而,如果指定了 --max-warnings 且总警告数超过指定阈值,ESLint 会以错误状态退出。
🌐 Normally, if ESLint runs and finds no errors (only warnings), it exits with a success exit status. However, if --max-warnings is specified and the total warning count is greater than the specified threshold, ESLint exits with an error status.
--max-warnings 示例
🌐 --max-warnings example
npm
npx eslint --max-warnings 10 file.js
yarn
yarn dlx eslint --max-warnings 10 file.js
pnpm
pnpm dlx eslint --max-warnings 10 file.js
bun
bunx eslint --max-warnings 10 file.js
输出
🌐 Output
-o, --output-file
将 linting 结果的输出写入指定文件。
🌐 Write the output of linting results to a specified file.
- 参数类型:字符串。文件路径。
- 多个参数:无
-o,--output-file 示例
🌐 -o, --output-file example
npm
npx eslint -o ./test/test.html
yarn
yarn dlx eslint -o ./test/test.html
pnpm
pnpm dlx eslint -o ./test/test.html
bun
bunx eslint -o ./test/test.html
-f, --format
此选项指定控制台的输出格式。
🌐 This option specifies the output format for the console.
如果你使用的是在局部文件中定义的自定义格式化程序,则可以指定自定义格式化程序文件的路径。
🌐 If you are using a custom formatter defined in a local file, you can specify the path to the custom formatter file.
通过 npm 安装的格式化程序可以有或没有 eslint-formatter- 前缀来解析。
🌐 An npm-installed formatter is resolved with or without eslint-formatter- prefix.
当指定时,给定的格式会输出到控制台。如果你想将该输出保存到文件中,可以在命令行中这样操作:
🌐 When specified, the given format is output to the console. If you’d like to save that output into a file, you can do so on the command line like so:
npm
# Saves the output into the `results.json` file.
npx eslint -f json file.js > results.json
yarn
# Saves the output into the `results.json` file.
yarn dlx eslint -f json file.js > results.json
pnpm
# Saves the output into the `results.json` file.
pnpm dlx eslint -f json file.js > results.json
bun
# Saves the output into the `results.json` file.
bunx eslint -f json file.js > results.json
-f,--format 示例
🌐 -f, --format example
使用内置的 json 格式化器:
🌐 Use the built-in json formatter:
npm
npx eslint --format json file.js
yarn
yarn dlx eslint --format json file.js
pnpm
pnpm dlx eslint --format json file.js
bun
bunx eslint --format json file.js
使用局部自定义格式化程序:
🌐 Use a local custom formatter:
npm
npx eslint -f ./customformat.js file.js
yarn
yarn dlx eslint -f ./customformat.js file.js
pnpm
pnpm dlx eslint -f ./customformat.js file.js
bun
bunx eslint -f ./customformat.js file.js
使用 npm 安装的格式化程序:
🌐 Use an npm-installed formatter:
npm
npm install eslint-formatter-pretty
yarn
yarn add eslint-formatter-pretty
pnpm
pnpm add eslint-formatter-pretty
bun
bun add eslint-formatter-pretty
然后运行以下命令之一
🌐 Then run one of the following commands
npm
npx eslint -f pretty file.js
yarn
yarn dlx eslint -f pretty file.js
pnpm
pnpm dlx eslint -f pretty file.js
bun
bunx eslint -f pretty file.js
或者
🌐 or alternatively
npm
npx eslint -f eslint-formatter-pretty file.js
yarn
yarn dlx eslint -f eslint-formatter-pretty file.js
pnpm
pnpm dlx eslint -f eslint-formatter-pretty file.js
bun
bunx eslint -f eslint-formatter-pretty file.js
--color 和 --no-color
🌐 --color and --no-color
这些选项强制启用/禁用彩色输出。
🌐 These options force the enabling/disabling of colorized output.
- 参数类型:无参数。
你可以使用这些选项来覆盖默认行为,默认行为是启用彩色输出,除非未检测到 TTY,例如当通过 cat 或 less 管道传输 eslint 时。
🌐 You can use these options to override the default behavior, which is to enable colorized output unless no TTY is detected, such as when piping eslint through cat or less.
--color 和 --no-color 示例
🌐 --color and --no-color example
npm
npx eslint --color file.js | cat
yarn
yarn dlx eslint --color file.js | cat
pnpm
pnpm dlx eslint --color file.js | cat
bun
bunx eslint --color file.js | cat
npm
npx eslint --no-color file.js
yarn
yarn dlx eslint --no-color file.js
pnpm
pnpm dlx eslint --no-color file.js
bun
bunx eslint --no-color file.js
内联配置注释
🌐 Inline Configuration Comments
--no-inline-config
此选项可防止像 /*eslint-disable*/ 或 /*global foo*/ 这样的内联注释产生任何效果。
🌐 This option prevents inline comments like /*eslint-disable*/ or
/*global foo*/ from having any effect.
- 参数类型:无参数。
这允许你在不修改文件的情况下设置 ESLint 配置。所有内联配置注释都会被忽略,例如:
🌐 This allows you to set an ESLint config without files modifying it. All inline config comments are ignored, such as:
/*eslint-disable*//*eslint-enable*//*global*//*eslint*/// eslint-disable-line// eslint-disable-next-line
--no-inline-config 示例
🌐 --no-inline-config example
npm
npx eslint --no-inline-config file.js
yarn
yarn dlx eslint --no-inline-config file.js
pnpm
pnpm dlx eslint --no-inline-config file.js
bun
bunx eslint --no-inline-config file.js
--report-unused-disable-directives
此选项会导致 ESLint 在本行本来不会报告任何错误的情况下,报告像 // eslint-disable-line 这样的指令注释。
🌐 This option causes ESLint to report directive comments like // eslint-disable-line when no errors would have been reported on that line anyway.
- 参数类型:无参数。
通过清理不再适用的旧 eslint-disable 和 eslint-enable 注释,这可以有助于防止未来的错误意外被抑制。
🌐 This can be useful to prevent future errors from unexpectedly being suppressed, by cleaning up old eslint-disable and eslint-enable comments which are no longer applicable.
--report-unused-disable-directives 示例
🌐 --report-unused-disable-directives example
npm
npx eslint --report-unused-disable-directives file.js
yarn
yarn dlx eslint --report-unused-disable-directives file.js
pnpm
pnpm dlx eslint --report-unused-disable-directives file.js
bun
bunx eslint --report-unused-disable-directives file.js
--report-unused-disable-directives-severity
与 --report-unused-disable-directives 相同,但允许你指定报告错误的严重级别(error、warn、off)。这两个选项中一次只能使用一个。
🌐 Same as --report-unused-disable-directives, but allows you to specify the severity level (error, warn, off) of the reported errors. Only one of these two options can be used at a time.
- 参数类型:字符串。取以下值之一:
off(或0)warn(或1)error(或2)
- 多个参数:无
- 默认值:默认情况下,使用
linterOptions.reportUnusedDisableDirectives配置设置(其默认值为"warn")。
--report-unused-disable-directives-severity 示例
🌐 --report-unused-disable-directives-severity example
npm
npx eslint --report-unused-disable-directives-severity warn file.js
yarn
yarn dlx eslint --report-unused-disable-directives-severity warn file.js
pnpm
pnpm dlx eslint --report-unused-disable-directives-severity warn file.js
bun
bunx eslint --report-unused-disable-directives-severity warn file.js
--report-unused-inline-configs
此选项会导致 ESLint 报告内联配置注释,例如 /* eslint rule-name: "error" */,其规则严重性和任何选项都与已配置的内容匹配。
🌐 This option causes ESLint to report inline config comments like /* eslint rule-name: "error" */ whose rule severity and any options match what’s already been configured.
- 参数类型:字符串。取以下值之一:
off(或0)warn(或1)error(或2)
- 多个参数:无
- 默认值:默认情况下,使用
linterOptions.reportUnusedInlineConfigs配置设置(其默认值为"off")。
这对于保持文件整洁并避免误导性杂乱可能是有用的。内联配置注释的目的是以某种方式改变 ESLint 的行为:如果它们没有改变任何东西,就没有理由保留它们。
🌐 This can be useful to keep files clean and devoid of misleading clutter. Inline config comments are meant to change ESLint’s behavior in some way: if they change nothing, there is no reason to leave them in.
--report-unused-inline-configs 示例
🌐 --report-unused-inline-configs example
npx eslint --report-unused-inline-configs error file.js
缓存
🌐 Caching
--cache
存储已处理文件的信息,以便仅对已更改的文件进行操作。启用此选项可以显著提高 ESLint 的运行性能,因为它确保只对已更改的文件进行 lint。
默认情况下,缓存存储在 .eslintcache 中。
🌐 Store the info about processed files in order to only operate on the changed ones. Enabling this option can dramatically improve ESLint’s run time performance by ensuring that only changed files are linted.
The cache is stored in .eslintcache by default.
- 参数类型:无参数。
如果你使用 --cache 运行 ESLint,然后再不使用 --cache 运行 ESLint,.eslintcache 文件将被删除。这是必要的,因为 lint 的结果可能会改变并使 .eslintcache 无效。如果你想控制缓存文件被删除的时间,请使用 --cache-location 指定缓存文件的备用位置。
🌐 If you run ESLint with --cache and then run ESLint without --cache, the .eslintcache file will be deleted. This is necessary because the results of the lint might change and make .eslintcache invalid. If you want to control when the cache file is deleted, then use --cache-location to specify an alternate location for the cache file.
自动修复的文件不会被放入缓存。后续不会触发自动修复的 lint 操作将把它放入缓存。
🌐 Autofixed files are not placed in the cache. Subsequent linting that does not trigger an autofix will place it in the cache.
--cache 示例
🌐 --cache example
npm
npx eslint --cache file.js
yarn
yarn dlx eslint --cache file.js
pnpm
pnpm dlx eslint --cache file.js
bun
bunx eslint --cache file.js
--cache-file
已弃用:请改用 --cache-location。
缓存文件的路径。如果未指定,则使用 .eslintcache。该文件将在执行 eslint 命令的目录中创建。
🌐 Path to the cache file. If none specified .eslintcache is used. The file is created in the directory where the eslint command is executed.
--cache-location
指定缓存位置的路径。可以是文件或目录。
🌐 Specify the path to the cache location. Can be a file or a directory.
- 参数类型:字符串。文件或目录的路径。如果指定的是目录,则在指定的文件夹内创建一个缓存文件。文件名基于当前工作目录的哈希值,例如:
.cache_hashOfCWD。 - 多个参数:无
- 默认值:如果未指定位置,将使用
.eslintcache。该文件将在执行eslint命令的目录中创建。
如果缓存目录不存在,请确保在 *nix 系统上添加尾部 /,在 Windows 上添加 \。否则,该路径将被视为一个文件。
🌐 If the directory for the cache does not exist make sure you add a trailing / on *nix systems or \ on Windows. Otherwise, the path is assumed to be a file.
--cache-location 示例
🌐 --cache-location example
npm
npx eslint "src/**/*.js" --cache --cache-location "/Users/user/.eslintcache/"
yarn
yarn dlx eslint "src/**/*.js" --cache --cache-location "/Users/user/.eslintcache/"
pnpm
pnpm dlx eslint "src/**/*.js" --cache --cache-location "/Users/user/.eslintcache/"
bun
bunx eslint "src/**/*.js" --cache --cache-location "/Users/user/.eslintcache/"
--cache-strategy
用于检测更改文件的缓存策略。
🌐 Strategy for the cache to use for detecting changed files.
- 参数类型:字符串。取以下值之一:
metadatacontent
- 多个参数:无
- 默认值:
metadata
content 策略在文件内容未改变时其修改时间仍发生变化的情况下可能很有用。例如,这种情况可能发生在 git 操作期间,比如 git clone,因为 git 不会跟踪文件的修改时间。
🌐 The content strategy can be useful in cases where the modification time of your files changes even if their contents have not. For example, this can happen during git operations like git clone because git does not track file modification time.
--cache-strategy 示例
🌐 --cache-strategy example
npm
npx eslint "src/**/*.js" --cache --cache-strategy content
yarn
yarn dlx eslint "src/**/*.js" --cache --cache-strategy content
pnpm
pnpm dlx eslint "src/**/*.js" --cache --cache-strategy content
bun
bunx eslint "src/**/*.js" --cache --cache-strategy content
抑制违规行为
🌐 Suppress Violations
--suppress-all
抑制现有违规行为,以便在后续运行中不会被报告。它允许你启用一个或多个 lint 规则,并且仅在出现新的违规行为时收到通知。默认情况下,抑制信息存储在 eslint-suppressions.json 中,除非 --suppressions-location 另有指定。文件会随新的抑制信息进行更新。
🌐 Suppresses existing violations, so that they are not being reported in subsequent runs. It allows you to enable one or more lint rules and be notified only when new violations show up. The suppressions are stored in eslint-suppressions.json by default, unless otherwise specified by --suppressions-location. The file gets updated with the new suppressions.
- 参数类型:无参数。
--suppress-all 示例
🌐 --suppress-all example
npm
npx eslint "src/**/*.js" --suppress-all
yarn
yarn dlx eslint "src/**/*.js" --suppress-all
pnpm
pnpm dlx eslint "src/**/*.js" --suppress-all
bun
bunx eslint "src/**/*.js" --suppress-all
--suppress-rule
抑制特定规则的违规,以便在后续运行中不被报告。与 --suppress-all 类似,抑制通常默认存储在 eslint-suppressions.json 中,除非由 --suppressions-location 另行指定。该文件会随新的抑制而更新。
🌐 Suppresses violations for specific rules, so that they are not being reported in subsequent runs. Similar to --suppress-all, the suppressions are stored in eslint-suppressions.json by default, unless otherwise specified by --suppressions-location. The file gets updated with the new suppressions.
- 参数类型:字符串。规则 ID。
- 多个参数:是
--suppress-rule 示例
🌐 --suppress-rule example
npm
npx eslint "src/**/*.js" --suppress-rule no-console --suppress-rule indent
yarn
yarn dlx eslint "src/**/*.js" --suppress-rule no-console --suppress-rule indent
pnpm
pnpm dlx eslint "src/**/*.js" --suppress-rule no-console --suppress-rule indent
bun
bunx eslint "src/**/*.js" --suppress-rule no-console --suppress-rule indent
--suppressions-location
指定抑制位置的路径。可以是文件或目录。
🌐 Specify the path to the suppressions location. Can be a file or a directory.
- 参数类型:字符串。文件路径。如果指定的是目录,则会在指定文件夹内创建一个缓存文件。文件名基于当前工作目录的哈希值,例如:
suppressions_hashOfCWD - 多个参数:无
- 默认值:如果未指定位置,将使用
eslint-suppressions.json。该文件将在执行eslint命令的目录中创建。
--suppressions-location 示例
🌐 --suppressions-location example
npm
npx eslint "src/**/*.js" --suppressions-location ".eslint-suppressions-example.json"
yarn
yarn dlx eslint "src/**/*.js" --suppressions-location ".eslint-suppressions-example.json"
pnpm
pnpm dlx eslint "src/**/*.js" --suppressions-location ".eslint-suppressions-example.json"
bun
bunx eslint "src/**/*.js" --suppressions-location ".eslint-suppressions-example.json"
--prune-suppressions
从抑制文件中修剪未使用的抑制项。当你已解决一个或多个被抑制的违规时,此选项很有用。
🌐 Prune unused suppressions from the suppressions file. This option is useful when you addressed one or more of the suppressed violations.
- 参数类型:无参数。
--prune-suppressions 示例
🌐 --prune-suppressions example
npm
npx eslint "src/**/*.js" --prune-suppressions
yarn
yarn dlx eslint "src/**/*.js" --prune-suppressions
pnpm
pnpm dlx eslint "src/**/*.js" --prune-suppressions
bun
bunx eslint "src/**/*.js" --prune-suppressions
--pass-on-unpruned-suppressions
忽略未使用的抑制。默认情况下,如果抑制文件中存在未使用的抑制,ESLint 会以退出代码 2 退出并显示错误信息。当你使用此标志时,未使用的抑制不会影响退出代码,ESLint 也不会输出关于未使用抑制的错误。
🌐 Ignore unused suppressions. By default, ESLint exits with exit code 2 and displays an error message if there are unused suppressions in the suppressions file. When you use this flag, unused suppressions do not affect the exit code and ESLint doesn’t output an error about unused suppressions.
- 参数类型:无参数。
--pass-on-unpruned-suppressions 示例
🌐 --pass-on-unpruned-suppressions example
npm
npx eslint "src/**/*.js" --pass-on-unpruned-suppressions
yarn
yarn dlx eslint "src/**/*.js" --pass-on-unpruned-suppressions
pnpm
pnpm dlx eslint "src/**/*.js" --pass-on-unpruned-suppressions
bun
bunx eslint "src/**/*.js" --pass-on-unpruned-suppressions
其他
🌐 Miscellaneous
--init
此选项运行 npm init @eslint/config 来启动配置初始化向导。它旨在通过回答几个问题来帮助新用户快速创建 eslint.config.js 文件。使用此标志时,CLI 不会执行代码检查。
🌐 This option runs npm init @eslint/config to start the config initialization wizard. It’s designed to help new users quickly create an eslint.config.js file by answering a few questions. When you use this flag, the CLI does not perform linting.
- 参数类型:无参数。
生成的配置文件在当前目录中创建。
🌐 The resulting configuration file is created in the current directory.
--init 示例
🌐 --init example
npm
npx eslint --init
yarn
yarn dlx eslint --init
pnpm
pnpm dlx eslint --init
bun
bunx eslint --init
--env-info
此选项输出有关执行环境的信息,包括 Node.js、npm 的版本以及 ESLint 的局部和全局安装。
🌐 This option outputs information about the execution environment, including the version of Node.js, npm, and local and global installations of ESLint.
- 参数类型:无参数。
ESLint 团队可能会要求提供此信息以帮助解决错误。当你使用此标志时,CLI 不执行 linting。
🌐 The ESLint team may ask for this information to help solve bugs. When you use this flag, the CLI does not perform linting.
--env-info 示例
🌐 --env-info example
npm
npx eslint --env-info
yarn
yarn dlx eslint --env-info
pnpm
pnpm dlx eslint --env-info
bun
bunx eslint --env-info
--no-error-on-unmatched-pattern
此选项可以在引用的通配符模式未匹配时防止错误。当你的 shell 无法匹配通配符时,这不会防止错误。
🌐 This option prevents errors when a quoted glob pattern is unmatched. This does not prevent errors when your shell can’t match a glob.
- 参数类型:无参数。
--no-error-on-unmatched-pattern 示例
🌐 --no-error-on-unmatched-pattern example
npm
npx eslint --no-error-on-unmatched-pattern --ext .ts "lib/*"
yarn
yarn dlx eslint --no-error-on-unmatched-pattern --ext .ts "lib/*"
pnpm
pnpm dlx eslint --no-error-on-unmatched-pattern --ext .ts "lib/*"
bun
bunx eslint --no-error-on-unmatched-pattern --ext .ts "lib/*"
--exit-on-fatal-error
此选项会导致 ESLint 在发生一个或多个致命解析错误时以退出代码 2 退出。没有此选项时,ESLint 会将致命解析错误报告为规则违规。
🌐 This option causes ESLint to exit with exit code 2 if one or more fatal parsing errors occur. Without this option, ESLint reports fatal parsing errors as rule violations.
- 参数类型:无参数。
--exit-on-fatal-error 示例
🌐 --exit-on-fatal-error example
npm
npx eslint --exit-on-fatal-error file.js
yarn
yarn dlx eslint --exit-on-fatal-error file.js
pnpm
pnpm dlx eslint --exit-on-fatal-error file.js
bun
bunx eslint --exit-on-fatal-error file.js
--no-warn-ignored
当显式传递被忽略的文件名时,此选项会抑制 File ignored by default 和 File ignored because of a matching ignore pattern 警告。当与 --max-warnings 0 配合使用时非常有用,因为它可以防止由于上述警告导致的退出代码 1。
🌐 This option suppresses both File ignored by default and File ignored because of a matching ignore pattern warnings when an ignored filename is passed explicitly. It is useful when paired with --max-warnings 0 as it will prevent exit code 1 due to the aforementioned warning.
- 参数类型:无参数。
--no-warn-ignored 示例
🌐 --no-warn-ignored example
npm
npx eslint --no-warn-ignored --max-warnings 0 ignored-file.js
yarn
yarn dlx eslint --no-warn-ignored --max-warnings 0 ignored-file.js
pnpm
pnpm dlx eslint --no-warn-ignored --max-warnings 0 ignored-file.js
bun
bunx eslint --no-warn-ignored --max-warnings 0 ignored-file.js
--pass-on-no-patterns
此选项允许 ESLint 在未传递任何文件或目录模式时以代码 0 退出。没有此选项,ESLint 会假设你想使用 . 作为模式。
🌐 This option allows ESLint to exit with code 0 when no file or directory patterns are passed. Without this option, ESLint assumes you want to use . as the pattern.
- 参数类型:无参数。
--pass-on-no-patterns 示例
🌐 --pass-on-no-patterns example
npm
npx eslint --pass-on-no-patterns
yarn
yarn dlx eslint --pass-on-no-patterns
pnpm
pnpm dlx eslint --pass-on-no-patterns
bun
bunx eslint --pass-on-no-patterns
--debug
此选项将调试信息输出到控制台。在 ESLint 命令行调用中添加此标志,以便在命令运行时获得额外的调试信息。
🌐 This option outputs debugging information to the console. Add this flag to an ESLint command line invocation in order to get extra debugging information while the command runs.
- 参数类型:无参数。
当你遇到问题并且难以定位时,这些信息非常有用。ESLint 团队可能会请求这些调试信息以帮助解决错误。
🌐 This information is useful when you’re seeing a problem and having a hard time pinpointing it. The ESLint team may ask for this debugging information to help solve bugs.
--debug 示例
🌐 --debug example
npm
npx eslint --debug test.js
yarn
yarn dlx eslint --debug test.js
pnpm
pnpm dlx eslint --debug test.js
bun
bunx eslint --debug test.js
-h, --help
此选项会输出帮助菜单,显示所有可用选项。当此选项存在时,所有其他选项将被忽略。当你使用此标志时,CLI 不会执行 linting。
🌐 This option outputs the help menu, displaying all of the available options. All other options are ignored when this is present. When you use this flag, the CLI does not perform linting.
- 参数类型:无参数。
-h,--help 示例
🌐 -h, --help example
npm
npx eslint --help
yarn
yarn dlx eslint --help
pnpm
pnpm dlx eslint --help
bun
bunx eslint --help
-v, --version
此选项会将当前的 ESLint 版本输出到控制台。当此选项存在时,所有其他选项都会被忽略。使用此标志时,CLI 不会执行代码检查。
🌐 This option outputs the current ESLint version onto the console. All other options are ignored when this is present. When you use this flag, the CLI does not perform linting.
- 参数类型:无参数。
-v,--version 示例
🌐 -v, --version example
npm
npx eslint --version
yarn
yarn dlx eslint --version
pnpm
pnpm dlx eslint --version
bun
bunx eslint --version
--print-config
此选项输出将用于所传文件的配置。启用时,不会执行任何 lint 操作,只有与配置相关的选项有效。当使用此标志时,CLI 不会执行 lint。
🌐 This option outputs the configuration to be used for the file passed. When present, no linting is performed and only config-related options are valid. When you use this flag, the CLI does not perform linting.
- 参数类型:字符串。文件路径。
- 多个参数:无
--print-config 示例
🌐 --print-config example
npm
npx eslint --print-config file.js
yarn
yarn dlx eslint --print-config file.js
pnpm
pnpm dlx eslint --print-config file.js
bun
bunx eslint --print-config file.js
--stats
此选项向传递给格式化程序的 result 对象(参见 Stats CLI usage)添加一系列详细的性能统计信息(参见 Stats type),例如 parse、fix 和 lint 时间(每条规则的时间)。
🌐 This option adds a series of detailed performance statistics (see Stats type) such as the parse-, fix- and lint-times (time per rule) to result objects that are passed to the formatter (see Stats CLI usage).
- 参数类型:无参数。
此选项旨在与显示统计信息的自定义格式化程序一起使用。它也可以与内置的 json 格式化程序一起使用。
🌐 This option is intended for use with custom formatters that display statistics. It can also be used with the built-in json formatter.
--stats 示例
🌐 --stats example
npm
npx eslint --stats --format json file.js
yarn
yarn dlx eslint --stats --format json file.js
pnpm
pnpm dlx eslint --stats --format json file.js
bun
bunx eslint --stats --format json file.js
--flag
此选项为 ESLint 启用一个或多个功能标志。
🌐 This option enables one or more feature flags for ESLint.
- 参数类型:字符串。一个特性标识符。
- 多个参数:是
--flag 示例
🌐 --flag example
npm
npx eslint --flag x_feature file.js
yarn
yarn dlx eslint --flag x_feature file.js
pnpm
pnpm dlx eslint --flag x_feature file.js
bun
bunx eslint --flag x_feature file.js
--mcp
此选项启动 ESLint MCP 服务器,用于 AI 代理。
🌐 This option starts the ESLint MCP server for use with AI agents.
- 参数类型:无参数。
- 多个参数:无
--mcp 示例
🌐 --mcp example
npm
npx eslint --mcp
yarn
yarn dlx eslint --mcp
pnpm
pnpm dlx eslint --mcp
bun
bunx eslint --mcp
--concurrency
此选项控制用于 lint 文件的工作线程数。
🌐 This option controls the number of worker threads used to lint files.
- 参数类型: 整数|字符串。一个正整数,
auto或off。 - 多个参数:无
- 默认值:
off
值 off 会导致所有文件在主线程中进行 lint 检查。值 auto 会尝试自动确定最佳设置。
🌐 The value off causes all files to be linted in the main thread. The value auto attempts to determine the best setting automatically.
--concurrency 示例
🌐 --concurrency example
npm
npx eslint --concurrency auto
yarn
yarn dlx eslint --concurrency auto
pnpm
pnpm dlx eslint --concurrency auto
bun
bunx eslint --concurrency auto
退出码
🌐 Exit Codes
对文件进行 linting 时,ESLint 会使用以下退出代码之一退出:
🌐 When linting files, ESLint exits with one of the following exit codes:
0:Lint 检查成功,没有 lint 错误。如果设置了--max-warnings标志为n,lint 警告的数量最多为n。1:代码检查成功,但存在至少一个代码检查错误,或者代码检查警告的数量超过了--max-warnings选项允许的数量。2:由于配置问题或内部错误,检查不成功。