@caspeco/eslint-config-react

中文文档
5.5.1发布于 2026/10/20MITTypeScriptES Module构建来源已验证近 30 天下载 3246

Caspeco ESLint configuration for React projects

原始使用文档
文档目录16 节
  1. Installation
  2. Migrating from v4.x
  3. Usage
  4. React Compiler (opt-in)
  5. What's Included
  6. Base TypeScript Configuration
  7. React-Specific Configuration
  8. Peer Dependencies
  9. ESLint 10
  10. Plugins
  11. eslint-plugin-react
  12. eslint-plugin-react-hooks
  13. eslint-plugin-react-refresh
  14. caspeco-react-plugin
  15. Relationship with @caspeco/eslint-config-ts
  16. License

@caspeco/eslint-config-react

Caspeco ESLint configuration for React + TypeScript projects.

Installation

npm install --save-dev @caspeco/eslint-config-react

Migrating from v4.x

If you're upgrading from @caspeco/eslint-config v4.x, use the automated migration script:

# Preview changes
npx caspeco-react-migrate-v5 src/ --dry-run

# Apply changes
npx caspeco-react-migrate-v5 src/

This updates the plugin namespace from caspeco/ to caspeco-react/. See the Migration Guide for details.

Usage

Create an eslint.config.js file in your project root:

import config from "@caspeco/eslint-config-react";

export default [{ ignores: ["dist/**/*", "build/**/*"] }, ...config];

React Compiler (opt-in)

If your project has adopted the React Compiler, use the /compiler entry point instead. It is a drop-in replacement that enables the full eslint-plugin-react-hooks recommended ruleset, including the React Compiler rules (react-hooks/purity, react-hooks/static-components, react-hooks/use-memo, react-hooks/immutability, react-hooks/set-state-in-render, and more):

import config from "@caspeco/eslint-config-react/compiler";

export default [{ ignores: ["dist/**/*", "build/**/*"] }, ...config];

The default config (@caspeco/eslint-config-react) intentionally enables only react-hooks/rules-of-hooks and react-hooks/exhaustive-deps, so teams that have not yet adopted the React Compiler are not flooded with compiler-specific warnings.

What's Included

This configuration includes everything from our TypeScript config plus React-specific rules:

Base TypeScript Configuration

  • TypeScript ESLint - recommended-type-checked config
  • No Barrel Files - Prevents barrel file usage
  • File Naming Conventions - Enforces kebab-case for files and folders
  • Prettier Integration - Compatible with Prettier formatting

React-Specific Configuration

  • React Plugin - Core React linting rules
  • React Hooks - Enforces rules of hooks
  • React Refresh - Fast Refresh support for Vite/development
  • Caspeco Plugin - Custom rules for Caspeco projects (Chakra UI import restrictions)

Peer Dependencies

This package requires the following peer dependencies (automatically installed by npm 7+):

  • eslint (9 or 10)
  • eslint-plugin-react-hooks
  • eslint-plugin-react-refresh
  • globals

See package.json for specific version requirements.

Note: Additional TypeScript-related peer dependencies are inherited from @caspeco/eslint-config-ts (installed automatically as a regular dependency).

eslint-plugin-react is a regular dependency, not a peer. It has no release that supports ESLint 10 yet, so this package patches it with fixupRule from @eslint/compat.

ESLint 10

  • Remove eslint-plugin-react from your own package.json, or npm fails with ERESOLVE.
  • npm prints npm warn ERESOLVE overriding peer dependency for eslint-plugin-react. The install succeeds and linting works.
  • Installs with strict peer dependencies (e.g. pnpm strict-peer-dependencies) fail until eslint-plugin-react supports ESLint 10.
  • Use @eslint/js 10 with ESLint 10. Its recommended adds no-useless-assignment, no-unassigned-vars and preserve-caught-error.
  • On ESLint 9, keep @eslint/js on ^9. A fresh install without a lockfile otherwise picks @eslint/js 10.

Plugins

eslint-plugin-react

eslint-plugin-react

Core React linting rules with the following customizations:

  • react-in-jsx-scope: off (not needed in modern React)
  • prop-types: off (using TypeScript instead)
  • display-name: off

eslint-plugin-react-hooks

eslint-plugin-react-hooks

Enforces:

  • Rules of Hooks (error)
  • Exhaustive dependencies (warning)

eslint-plugin-react-refresh

eslint-plugin-react-refresh

Ensures components are compatible with Fast Refresh in development.

caspeco-react-plugin

Custom React-specific plugin with Caspeco rules:

  • Discourages direct imports from @chakra-ui/react (use themed components instead)

Relationship with @caspeco/eslint-config-ts

This package depends on and extends @caspeco/eslint-config-ts, which is automatically installed as a dependency. This ensures React projects always use the same TypeScript rules without drift. If you're building a React project, use this package. For vanilla TypeScript projects, use @caspeco/eslint-config-ts.

License

MIT

版本与发布记录

@caspeco/eslint-config-react 共发布 17 个版本,首次发布于 2025/11/11;过去 12 个月发布了 17 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.5.1latest2026/10/2020 天前
5.5.02026/10/2020 天前
5.5.0-beta.0next2026/10/2020 天前
5.4.22026/08/122 个月前
5.4.12026/07/104 个月前
5.4.02026/07/094 个月前

关于 @caspeco/eslint-config-react 的常见问题

@caspeco/eslint-config-react 是什么?

Caspeco ESLint configuration for React projects

如何安装 @caspeco/eslint-config-react?

在项目目录运行 npm install @caspeco/eslint-config-react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:eslint(^9.39.4 || ^10.0.0)、globals(^17.4.0)、eslint-plugin-react-hooks(^7.1.1)、eslint-plugin-react-refresh(^0.5.4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 caspeco-react-migrate-v5,可以用 npx caspeco-react-migrate-v5 直接运行。

@caspeco/eslint-config-react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@caspeco/eslint-config-react 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@caspeco/eslint-config-react 可以商用吗?

@caspeco/eslint-config-react 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@caspeco/eslint-config-react 的下载量有多少?

根据 npm 官方下载统计,@caspeco/eslint-config-react 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,246 次,日均约 108 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@caspeco/eslint-config-react 还在维护吗?

最新版本 5.5.1 发布于 2026/10/20(20 天前);至今共发布 17 个版本,其中过去 12 个月发布了 17 个;首次发布于 2025/11/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。