eslint

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ESLint

ESLint

ESLint is the standard linter for JS/TS. v9 (2024/2025) moved to Flat Config (
eslint.config.js
), a major breaking change that simplifies configuration.
ESLint是JS/TS的标准代码检查工具。2024/2025推出的v9版本迁移到了Flat Config
eslint.config.js
),这是一项重大的突破性更新,简化了配置流程。

When to Use

适用场景

  • Enforcing Rules:
    no-unused-vars
    ,
    react-hooks/rules-of-hooks
    .
  • Code Quality: Catching bugs before they run.
  • 规则强制执行
    no-unused-vars
    react-hooks/rules-of-hooks
    等规则。
  • 代码质量保障:在代码运行前捕获潜在bug。

Core Concepts

核心概念

Flat Config (
eslint.config.js
)

Flat Config(
eslint.config.js

An array of objects. No more
extends
string hell.
js
export default [js.configs.recommended, { rules: { semi: "error" } }];
由对象组成的数组,告别了复杂的
extends
字符串配置。
js
export default [js.configs.recommended, { rules: { semi: "error" } }];

Plugins

插件

NPM packages that add rules.
eslint-plugin-react
.
用于新增规则的NPM包,例如
eslint-plugin-react

Parsers

解析器

@typescript-eslint/parser
allows ESLint to understand TS.
@typescript-eslint/parser
让ESLint能够识别TypeScript代码。

Best Practices (2025)

2025年最佳实践

Do:
  • Use Flat Config: Use the new format.
  • Use
    typescript-eslint
    : The typed linting rules are powerful (e.g.
    no-floating-promises
    ).
Don't:
  • Don't configure formatting rules: Disable all formatting rules (use Prettier or Biome for that). use
    eslint-config-prettier
    .
建议
  • 使用Flat Config:采用新的配置格式。
  • 使用
    typescript-eslint
    :其类型化检查功能强大(例如
    no-floating-promises
    规则)。
不建议
  • 不要配置格式化规则:禁用所有格式化规则(使用Prettier或Biome来处理格式化),可借助
    eslint-config-prettier
    实现。

References

参考资料