配置 ESLint

ESLint 旨在为你的用例提供灵活性和可配置性。你可以关闭每条规则并仅使用基本语法验证运行,或者混合搭配打包规则和你的自定义规则以满足你项目的需要。配置 ESLint 有两种主要方式:

¥ESLint is designed to be flexible and configurable for your use case. You can turn off every rule and run only with basic syntax validation or mix and match the bundled rules and your custom rules to fit the needs of your project. There are two primary ways to configure ESLint:

  1. 配置注释 - 使用 JavaScript 注释将配置信息直接嵌入到文件中。

    ¥Configuration Comments - use JavaScript comments to embed configuration information directly into a file.

  2. 配置文件 - 使用 JavaScript 文件指定整个目录及其所有子目录的配置信息。这可以是 eslint.config.js 文件的形式,ESLint 将自动查找并读取该文件,或者你可以在 命令行 上指定配置文件。

    ¥Configuration Files - use a JavaScript file to specify configuration information for an entire directory and all of its subdirectories. This can be in the form of an eslint.config.js file which ESLint will look for and read automatically, or you can specify a configuration file on the command line.

以下是你可以在 ESLint 中配置的一些选项:

¥Here are some of the options that you can configure in ESLint:

  • 全局变量 - 你的脚本在执行期间访问的其他全局变量。

    ¥Globals - the additional global variables your script accesses during execution.

  • 规则 - 启用了哪些规则以及处于什么错误级别。

    ¥Rules - which rules are enabled and at what error level.

  • 插件 - 哪些第三方插件定义了额外的规则、环境、配置等供 ESLint 使用。

    ¥Plugins - which third-party plugins define additional rules, environments, configs, etc. for ESLint to use.

所有这些选项都让你可以细粒度地控制 ESLint 如何处理你的代码。

¥All of these options give you fine-grained control over how ESLint treats your code.

目录

¥Table of Contents

配置文件

¥Configuration Files

配置语言选项

¥Configure Language Options

配置规则

¥Configure Rules

配置插件

¥Configure Plugins

配置解析器

¥Configure a Parser

忽略文件

¥Ignore Files

ESLint 中文网
粤ICP备13048890号