Skip to content

Commit

Permalink
feat: sync v8.31.0 (#94)
Browse files Browse the repository at this point in the history
* docs: User Guide Getting Started expansion

* docs: add options to check destructuring in no-underscore-dangle

eslint/eslint#16006

* docs: adjust some words

* docs: Add function call example for no-undefined

eslint/eslint#16712

* docs: check assignment patterns in no-underscore-dangle

eslint/eslint#16693

* update formatters

* Apply suggestions from code review

Co-authored-by: Strek <ssharishkumar@gmail.com>

---------

Co-authored-by: Strek <ssharishkumar@gmail.com>
  • Loading branch information
kecrily and harish-sethuraman committed Feb 25, 2023
1 parent 51d4fc6 commit 00cb6f6
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 76 deletions.
4 changes: 4 additions & 0 deletions src/rules/no-undefined.md
Expand Up @@ -56,6 +56,8 @@ if (foo === undefined) {
function foo(undefined) {
// ...
}

bar(undefined, "lorem");
```

:::
Expand All @@ -76,6 +78,8 @@ if (typeof foo === "undefined") {
}

global.undefined = "foo";

bar(void 0, "lorem");
```

:::
Expand Down
57 changes: 50 additions & 7 deletions src/rules/no-underscore-dangle.md
Expand Up @@ -53,13 +53,15 @@ const foo = (_bar) => {};

此规则选项为对象:

* `"allow"` 允许指定的标识符有悬空的下划线。
* `"allowAfterThis": false`(默认值)不允许在 `this` 对象的成员中使用悬空的下划线。
* `"allowAfterSuper": false`(默认值)不允许在 `super` 对象的成员中使用悬空的下划线。
* `"allowAfterThisConstructor": false`(默认值)不允许在 `this.constructor` 对象的成员中使用悬空的下划线。
* `"enforceInMethodNames": false`(默认值)允许在方法名称中使用悬空的下划线。
* `"enforceInClassFields": false`(默认值)允许在 es2022 类字段名中使用悬空的下划线。
* `"allowFunctionParams": true`(默认值)允许在函数参数名称中使用悬空的下划线。
* `"allow"` 允许指定的标识符有悬空的下划线
* `"allowAfterThis": false`(默认值)不允许在 `this` 对象的成员中使用悬空的下划线
* `"allowAfterSuper": false`(默认值)不允许在 `super` 对象的成员中使用悬空的下划线
* `"allowAfterThisConstructor": false`(默认值)不允许在 `this.constructor` 对象的成员中使用悬空的下划线
* `"enforceInMethodNames": false`(默认值)允许在方法名称中使用悬空的下划线
* `"enforceInClassFields": false`(默认值)允许在 es2022 类字段名中使用悬空的下划线
* `"allowInArrayDestructuring": true`(默认值)允许在由数组解构分配的变量名称中使用悬空的下划线
* `"allowInObjectDestructuring": true`(默认值)允许在对象解构分配的变量名称中使用悬空的下划线
* `"allowFunctionParams": true`(默认值)允许在函数参数名称中使用悬空的下划线

### allow

Expand Down Expand Up @@ -181,6 +183,47 @@ class Foo {

:::

### allowInArrayDestructuring

使用此规则与 `{ "allowInArrayDestructuring": false }` 选项的**错误**示例:

::: incorrect

```js
/*eslint no-underscore-dangle: ["error", { "allowInArrayDestructuring": false }]*/
const [_foo, _bar] = list;
const [foo_, ..._bar] = list;
const [foo, [bar, _baz]] = list;
```

:::

### allowInObjectDestructuring

使用此规则与 `{ "allowInObjectDestructuring": false }` 选项的**错误**示例:

::: incorrect

```js
/*eslint no-underscore-dangle: ["error", { "allowInObjectDestructuring": false }]*/
const { foo, bar: _bar } = collection;
const { foo, bar, _baz } = collection;
```

:::

使用此规则与 `{ "allowInObjectDestructuring": false }` 选项的**正确**示例:

::: correct

```js
/*eslint no-underscore-dangle: ["error", { "allowInObjectDestructuring": false }]*/
const { foo, bar, _baz: { a, b } } = collection;
const { foo, bar, _baz: baz } = collection;
```

:::

### allowFunctionParams

使用此规则与 `{ "allowFunctionParams": false }` 选项的**错误**示例:
Expand Down
18 changes: 9 additions & 9 deletions src/user-guide/configuring/configuration-files-new.md
Expand Up @@ -35,21 +35,21 @@ export default [

每个配置对象都包括了 ESLint 检查一组文件所需的所有信息。配置对象由以下属性组成:

* `files` - 用于表示配置适用的文件范围的 glob 模式数组。在没有指定的情况下,配置对象适用于所有文件
* `ignores` - 一个表示配置对象不应适用的文件的 glob 模式数组。如果没有指定,配置对象将适用于所有由 `files` 匹配的文件。
* `languageOptions` - 一个对象,包含与如何为 linting 配置 JavaScript 有关的设置
* `files` - 表示配置适用的文件范围的 glob 模式数组。在没有指定的情况下,配置对象适用于所有与其他配置对象匹配的文件
* `ignores` - 表示配置对象不应适用的文件的 glob 模式数组。如果没有指定,配置对象将适用于所有由 `files` 匹配的文件。
* `languageOptions` - 包含如何配置检查过程中 JavaScript 设置的对
* `ecmaVersion` - 支持 ECMAScript 的版本。可以是任何年份(`2022`)或版本(`5`)。设置为 `"latest"` 则使用受支持的最新版本(默认为 `"latest"`)。
* `sourceType` - JavaScript 源码类型。传统脚本文件可以使用 `"script"`,ECMAScript 模块(ESM)可以用 `"module"` ,CommonJS 文件使用 `"commonjs`(默认情况下,用于 `.js``.mjs` 文件使用 `"module"``.cjs` 文件使用 `"commonjs"`
* `globals` - 用于指定额外对象的对象,这些对象应该在 linting 期间被添加到全局范围
* `parser` - 包含 `parse()`方法的对象,或者表示插件内解析器名称的字符串(如 `"pluginName/parserName"`,默认为 `"@/espree"`
* `sourceType` - JavaScript 源码类型。传统脚本文件可以使用 `"script"`,ECMAScript 模块(ESM)可以用 `"module"` ,CommonJS 文件使用 `"commonjs`(默认情况下,`.js``.mjs` 文件使用 `"module"``.cjs` 文件使用 `"commonjs"`
* `globals` - 指定额外对象的对象,这些对象应该在检查期间会被添加到全局范围
* `parser` - 包含 `parse()` 方法的对象,或者表示插件内解析器名称的字符串(如 `"pluginName/parserName"`,默认为 `"@/espree"`
* `parserOptions` - 指定额外选项的对象,直接传递给解析器的 `parser()` 方法。可用选项基于解析器。
* `linterOptions` - 对象,包含与提示过程有关的设置。
* `noInlineConfig` - 布尔值,表示是否允许内联配置
* `reportUnusedDisableDirectives` - 一个布尔值,表示是否应该跟踪和报告未用的禁用指令
* `noInlineConfig` - 表示是否允许内联配置布尔值
* `reportUnusedDisableDirectives` - 表示是否应该跟踪和报告未用的禁用指令的布尔值
* `processor` - 包含 `preprocess()``postprocess()` 方法的对象,或者表示插件内处理器名称的字符串(如 `"pluginName/processorName"`)。
* `plugins` - 包含插件名称与对应的插件对象的名值对对象。如果指定了 `files`,则只适用于与之匹配匹配的文件。
* `rules` - 包含规则配置的对象。如果指定了 `files``ignores`,则规则配置只适用于与之匹配匹配的文用。
* `settings` - 包括名值对的对象,这些信息应该对所有规则可用
* `settings` - 包含对所有规则可供的名值对的对象

### 指定 `files``ignores`

Expand Down
16 changes: 7 additions & 9 deletions src/user-guide/core-concepts.md
Expand Up @@ -47,38 +47,36 @@ ESLint 插件是一个包含 ESLint 规则、配置、解析器和环境变量

## 解析器

ESLint 解析器 converts code into an abstract syntax tree that ESLint can evaluate. By default, ESLint uses the built-in [Espree](https://github.com/eslint/espree) parser, which is compatible with standard JavaScript runtimes and versions.

ESLint 解析器将代码转换为 ESLint 可以评估的抽象语法树(AST, abstract syntax tree)。默认情况下,ESLint 使用内置的与标准 JavaScript运行时和版本兼容的 [Espree](https://github.com/eslint/espree) 解析器。

自定义解析器让 ESLint 可以解析非标准的 JavaScript 语法。通常自定义解析器会被包含在可共享配置或插件中,这一你就不需要直接使用它们了。

比如用于让 ESLint 可以解析 TypeScript 代码的 [@typescript-eslint/parser](https://www.npmjs.com/package/@typescript-eslint/parser) 解析器就被包含在 [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) 项目中。
比如用于让 ESLint 可以解析 TypeScript 代码的 [@typescript-eslint/parser](https://www.npmjs.com/package/@typescript-eslint/parser) 解析器就被包含在 [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) 项目中。

## 自定义处理器

ESLint 处理器可以从其他类型的文件中提取 JavaScript 代码,然后让 ESLint 对 JavaScript 代码进行检查。另外,你也可以在用 ESLint 解析 JavaScript 代码之前使用一个处理器对其进行处理
ESLint 处理器可以从其他类型的文件中提取 JavaScript 代码,然后让 ESLint 对 JavaScript 代码进行检查。另外,你也可以在用 ESLint 解析 JavaScript 代码之前使用处理器先对其进行处理

例如 [eslint-plugin-markdown](https://github.com/eslint/eslint-plugin-markdown) 就包括一个自定义处理器,让你可以对 Markdown 代码块内的 JavaScript 代码进行检查。

## 格式化工具

ESLint 格式化工具决定了命令行检查结果的样子
ESLint 格式化工具决定了命令行输出的检查结果的样子

更多信息请参见[格式化工具](./formatters/)

## 集成

ESLint 相关集成生态是使 ESLint 成为如此有用的工具的原因之一。例如,许多代码编辑器都有 ESLint 扩展,这让工作时,可以即刻在文件中查看相关的代码 ESLint 结果,这样你就不需要使用 ESLint CLI 来查看检查结果
ESLint 相关集成生态是使 ESLint 成为如此有用的工具的原因之一。例如,许多代码编辑器都有 ESLint 扩展,这让工作时,可以即刻在文件中查看相关的代码 ESLint 结果,这样你就不需要使用 ESLint 命令行来查看检查结果

更多信息请参见[集成](./integrations)

## CLI & Node.js API
## 命令行 & Node.js API

ESLint CLI 是一个命令行界面,让你可以在终端进行检查。CLI 有各种可以传递给命令的选项
ESLint 命令行是一个命令行界面,让你可以在终端进行检查。命令行有各种可以传递给命令的选项

ESLint 的 Node.js API 让你可以在 Node.js 代码中以编程的方式使用 ESLint。该 API 在开发插件、集成和其他与 ESLint 相关的工具时非常有用。

除非你以某种方式扩展 ESLint,否则你就应该使用 CLI
除非你要以某种方式扩展 ESLint,否则你就应该使用命令行

更多信息请参见[命令行界面](./command-line-interface)[Node.js API](../developer-guide/nodejs-api)

0 comments on commit 00cb6f6

Please sign in to comment.