🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@huaiyou/config-eslint

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@huaiyou/config-eslint

Shared ESLint configuration with flat config (ESLint 9.x)

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

@huaiyou/config-eslint

基于 ESLint 9.x Flat Config 的共享 ESLint 配置,支持 TypeScript 和 React。

📦 安装

pnpm add -D @huaiyou/config-eslint eslint typescript

🚀 快速开始

Base 配置(TypeScript 项目)

创建 eslint.config.js 文件:

import { base } from '@huaiyou/config-eslint';

export default base;

React 配置

对于 React 项目:

import { react } from '@huaiyou/config-eslint';

export default react;

✨ 特性

Base 配置

  • ESLint 9.x Flat Config: 使用最新的配置格式
  • TypeScript 支持: 完整的 TypeScript 类型检查
  • Import 排序: 自动排序和组织 import 语句
  • Prettier 集成: 与 Prettier 完美配合,无冲突
  • 严格规则: 推荐的最佳实践和代码规范

React 配置

继承 Base 配置,额外包含:

  • React 规则: React 最佳实践
  • Hooks 检查: React Hooks 使用规范
  • JSX 支持: 完整的 JSX 语法支持
  • 自动检测: 自动检测 React 版本

📋 规则说明

TypeScript 规则

规则设置说明
@typescript-eslint/no-unused-varserror禁止未使用的变量(忽略 _ 开头)
@typescript-eslint/no-explicit-anywarn警告使用 any 类型
@typescript-eslint/consistent-type-importserror强制使用 type import
@typescript-eslint/no-misused-promiseserror防止错误使用 Promise

Import 规则

规则设置说明
import/ordererror强制 import 顺序和分组
import/no-duplicateserror禁止重复 import
import/newline-after-importerrorimport 后需要空行

React 规则

规则设置说明
react/prop-typesoff关闭 PropTypes(使用 TS)
react/react-in-jsx-scopeoffReact 17+ 不需要
react-hooks/rules-of-hookserrorHooks 使用规则
react-hooks/exhaustive-depswarnHooks 依赖检查

🔧 自定义配置

扩展配置

import { base } from '@huaiyou/config-eslint';

export default [
  ...base,
  {
    rules: {
      // 你的自定义规则
      '@typescript-eslint/no-explicit-any': 'error',
    },
  },
];

忽略文件

import { base } from '@huaiyou/config-eslint';

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

针对特定文件的规则

import { react } from '@huaiyou/config-eslint';

export default [
  ...react,
  {
    files: ['**/*.test.{ts,tsx}'],
    rules: {
      '@typescript-eslint/no-explicit-any': 'off',
    },
  },
];

📝 配合 package.json 使用

{
  "scripts": {
    "lint": "eslint .",
    "lint:fix": "eslint . --fix"
  }
}

🔄 从 ESLint 8.x 迁移

ESLint 9.x 使用全新的 Flat Config 格式,主要变化:

  • 配置文件: .eslintrc.*eslint.config.js
  • 格式: 对象配置 → 数组配置
  • extends: 移除,使用数组展开
  • plugins: 新的插件系统

详见 ESLint Migration Guide

🤝 贡献

欢迎提交 Issue 和 Pull Request 来改进配置。

📄 License

MIT

FAQs

Package last updated on 07 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts