ESLint v9.16.0 发布

我们刚刚发布了 ESLint v9.16.0,这是 ESLint 的一次小版本升级。此版本添加了一些新功能,并修复了上一版本中发现的几个错误。

亮点

🌐 Highlights

sort-keysignoreComputedKeys 选项

🌐 ignoreComputedKeys option for sort-keys

此版本为 sort-keys 规则添加了一个新的布尔选项 ignoreComputedKeysignoreComputedKeys 通过将计算键视为组分隔符而不是组的一部分,从而允许对非计算名称的属性进行更一致的排序。 以下示例显示在没有 ignoreComputedKeys 选项的情况下,对对象字面量中的属性进行排序的预期结果。

🌐 This release adds a new boolean option ignoreComputedKeys to the sort-keys rule. ignoreComputedKeys allows a more consistent sorting of properties with non-computed names by treating computed keys as group separators rather than part of a group. The following example shows the expected sorting of properties in an object literal without the ignoreComputedKeys option.

使用 ignoreComputedKeys: false(默认)

const obj = { a: 10, b: 20, [c]: 7.5, d: 15 };

ignoreComputedKeys 设置为 true 时,计算出的键 c 可以出现在字面量中的任何位置,只要其他属性组是有序的。

🌐 When ignoreComputedKeys is set to true, the computed key c can appear anywhere in the literal, as long as the other groups of properties are sorted.

使用 ignoreComputedKeys: true

const obj = { a: 10, b: 20, [c]: 7.5, d: 15 };

or

const obj = { d: 15, [c]: 7.5, a: 10, b: 20 };

or

const obj = { a: 10, b: 20, d: 15, [c]: 7.5 };

etc.

与语言无关的 no-restricted-syntax

🌐 Language-agnostic no-restricted-syntax

此版本的另一个改进是能够将no-restricted-syntax规则用于任何语言。 这在以前的版本中已经可能,但现在官方支持并记录了语言插件的使用。

🌐 Another enhancement in this release is the ability to use the no-restricted-syntax rule with any language. This was already possible in previous releases, but now usage with language plugins is officially supported and documented.

在使用 @eslint/json 插件对 JSON 文件进行 lint 时,一个关于 null 使用发出警告的配置可能如下所示:

🌐 When linting JSON files with the @eslint/json plugin, a config that warns about the usage of null could look like this:

import json from "@eslint/json";

export default [
    {
        files: ["**/*.json"],
        language: "json/json",
        plugins: {
            json,
        },
        rules: {
            "no-restricted-syntax": [
                "warn",
                "Null" // AST selector for `null`
            ],
        },
    },
];

如果你希望基于 AST 选择器 限制项目中的语法,但不确定哪些节点代表特定代码,我们建议使用 代码浏览器

🌐 If you would like to restrict syntax in your project based on AST selectors but you’re unsure what nodes represent a particular code, we recommend using Code Explorer.

特性

🌐 Features

文档

🌐 Documentation

杂项

🌐 Chores

  • feb703b 事务: 升级到 @eslint/js@9.16.0 (#19195) (Francesco Trotta)
  • df9bf95 事务:更新 package.json 以适配 @eslint/js 版本发布(Jenkins)
  • f831893 事务:为 sort-keysignoreComputedKeys 选项添加类型 (#19184) (Tanuj Kanti)
  • 3afb8a1 杂项:将依赖 @eslint/json 更新到 ^0.8.0 (#19177) (Milos Djermanovic)
  • 1f77c53 杂项:向 package.json 添加 repository.directory 属性 (#19165) (루밀LuMir)
  • d460594 事务:将依赖 @arethetypeswrong/cli 更新到 ^0.17.0 (#19147) (renovate[bot])
  • 45cd4ea 重构:更新规则中的默认选项 (#19136) (Milos Djermanovic)

最新的 ESLint 新闻、案例研究、教程和资源。

ESLint v10.3.0 发布
1 min read

ESLint v10.3.0 发布

我们刚刚发布了 ESLint v10.3.0,这是 ESLint 的一次小版本升级。此版本添加了一些新功能,并修复了上一版本中发现的几个错误。

ESLint v10.2.1 发布
1 min read

ESLint v10.2.1 发布

我们刚刚发布了 ESLint v10.2.1,这是 ESLint 的一个补丁版本升级。本次发布修复了上一版本中发现的几个错误。

ESLint v10.2.0 发布
2 min read

ESLint v10.2.0 发布

我们刚刚发布了 ESLint v10.2.0,这是 ESLint 的一次小版本升级。此版本添加了一些新功能,并修复了上一版本中发现的几个错误。