rhine-lint 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +167 -57
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,81 +1,191 @@
1
1
  # Rhine Lint
2
2
 
3
- 内置 EsLint 与 Prettier 的代码风格包。可零配置直接使用 rl 命令。
3
+ <p align="center">
4
+ <img src="https://img.shields.io/npm/v/rhine-lint?style=flat-square" alt="npm version" />
5
+ <img src="https://img.shields.io/npm/l/rhine-lint?style=flat-square" alt="license" />
6
+ <img src="https://img.shields.io/badge/style-opinionated-blue?style=flat-square" alt="style" />
7
+ </p>
4
8
 
5
- 不建议在你的项目中,重复安装 eslint, prettier, typescript-eslint, 及各种插件包。
9
+ > **现在的 Web 开发中,配置 ESLint、Prettier、TypeScript 以及各种插件(React, Next.js, CSS, Markdown...)往往是一场噩梦。**
10
+ > 重复的样板代码、版本冲突、复杂的 Flat Config 迁移... **Rhine Lint** 旨在结束这一切。
6
11
 
7
- ## Performance
12
+ **Rhine Lint** 是一个「零配置」的现代化代码规范解决方案。它深度整合了 **ESLint (v9 Flat Config)** 与 **Prettier**,为你提供开箱即用的最佳实践。你无需再手动安装数十个 `eslint-plugin-*` 依赖,也无需编写数百行的配置文件。只需一个依赖,一行命令,即可获得顶级的代码质量守护。
8
13
 
9
- ```text
10
- 执行 rl 即执行 eslint . 和 prettier .
14
+ ## ✨ 特性 (Features)
11
15
 
12
- 执行 rl <filename> 即执行 eslint <filename> prettier <filename> .
16
+ - **⚡️ 零配置启动 (Zero Config)**: 默认提供适用于 TypeScript、React、Next.js 的最佳实践配置,安装即用。
17
+ - **🛠️ 统一工具链 (Unified Toolchain)**: 一个 `rl` 命令同时执行代码检查 (Lint) 和代码格式化 (Format)。
18
+ - **🏗️ 全栈支持 (Full Stack)**:
19
+ - **JavaScript / TypeScript**: 完整的类型检查支持。
20
+ - **Frontend**: React (v18/v19), React Hooks, JSX A11y.
21
+ - **Frameworks**: Next.js (Pages & App Router).
22
+ - **Styles**: CSS, SCSS format supports.
23
+ - **Others**: JSON, Markdown support.
24
+ - **🔧 智能配置生成 (Smart Config)**: 运行时动态生成配置文件,无需担心 ESLint/Prettier 配置文件污染项目根目录。
25
+ - **🧩 灵活扩展 (Extensible)**: 支持 `rhine-lint.config.ts` 进行规则覆盖或深度定制。
13
26
 
14
- 执行 rl --fix 即执行 eslint . --fix 和 prettier . --write
15
- ```
27
+ ## 📦 安装 (Installation)
16
28
 
17
- ## Install
29
+ 在你的项目中作为开发依赖安装:
18
30
 
19
31
  ```bash
32
+ # Bun (Recommended)
20
33
  bun add -D rhine-lint
34
+
35
+ # npm
36
+ npm install --save-dev rhine-lint
37
+
38
+ # pnpm
39
+ pnpm add -D rhine-lint
40
+
41
+ # yarn
42
+ yarn add -D rhine-lint
21
43
  ```
22
44
 
23
- ## Arguments
45
+ ## 🚀 快速开始 (Quick Start)
24
46
 
25
- ```text
26
- --config 指定配置文件路径
47
+ ### 命令行使用 (CLI)
27
48
 
28
- --fix 是否修复
49
+ 安装完成后,你可以直接使用 `rl` 命令:
29
50
 
30
- --level 指定项目种类 (js | ts | frontend | nextjs). 默认 frontend.
51
+ ```bash
52
+ # 检查当前目录下所有文件 (默认 lint + check format)
53
+ npx rl
54
+
55
+ # 自动修复所有可修复的代码风格问题
56
+ npx rl --fix
57
+
58
+ # 检查指定文件或目录
59
+ npx rl src/components
60
+
61
+ # 指定项目类型 (覆盖自动检测或默认值)
62
+ npx rl --level nextjs
31
63
  ```
32
64
 
33
- ## Config
34
- 会自动检测以下文件作为配置:
35
- ```text
36
- rhine-lint.config.js
37
- rhine-lint.config.ts
38
- rhine-lint.config.cjs
39
- rhine-lint.config.mjs
40
- rhine-lint.config.json
41
- config/rhine-lint.config.js
42
- config/rhine-lint.config.ts
43
- config/rhine-lint.config.cjs
44
- config/rhine-lint.config.mjs
45
- config/rhine-lint.config.json
65
+ ### 推荐配置
66
+
67
+ 在 `package.json` 中添加 scripts,方便日常使用:
68
+
69
+ ```json
70
+ {
71
+ "scripts": {
72
+ "lint": "rl",
73
+ "lint:fix": "rl --fix"
74
+ }
75
+ }
46
76
  ```
47
77
 
48
- 配置文件格式:
49
- ```ts
50
- export type Config = {
51
- level?: 'none' | 'js' | 'ts' | 'frontend' | 'nextjs',
52
- fix?: boolean,
53
- tsconfig?: string,
54
- eslint?: {
55
- scope?: {
56
- script?: boolean,
57
- typeChecked?: boolean,
58
- projectBaseTypeChecked?: boolean,
59
- frontend?: boolean,
60
- nextjs?: boolean,
61
- markdown?: boolean,
62
- json?: boolean,
63
- stylesheet?: boolean,
64
- ignorePrettier?: boolean,
65
- },
66
- config?: [
67
- // EsLint Flatten Config
68
- ],
69
- // Default false for Merge Mode, true for Overlay Mode
70
- overlay?: boolean,
78
+ ## ⚙️ 配置 (Configuration)
79
+
80
+ 虽然 Rhine Lint 是零配置的,但也支持通过配置文件进行深度定制。它会自动检测项目根目录下的 `rhine-lint.config.{ts,js,mjs,json}`。
81
+
82
+ ### 配置文件示例 (`rhine-lint.config.ts`)
83
+
84
+ ```typescript
85
+ import { type Config } from 'rhine-lint';
86
+
87
+ export default {
88
+ // 指定项目级别: 'js' | 'ts' | 'frontend' | 'nextjs'
89
+ // 默认为 'frontend'
90
+ level: 'nextjs',
91
+
92
+ // 是否默认开启修复模式 (可选)
93
+ fix: false,
94
+
95
+ // ESLint 专项配置
96
+ eslint: {
97
+ // 启用/禁用特定范围的规则
98
+ scope: {
99
+ frontend: true, // 开启前端规则 (React 等)
100
+ nextjs: true, // 开启 Next.js 规则
101
+ imoprtX: true, // 开启 Import 排序等规则
71
102
  },
72
- prettier?: {
73
- config?: {
74
- // Prettier Config
75
- },
76
- // Default false for Merge Mode, true for Overlay Mode
77
- overlay?: boolean,
103
+
104
+ // 自定义 ESLint 规则 (Flat Config 格式)
105
+ // 这里的配置会与默认配置合并
106
+ config: [
107
+ {
108
+ rules: {
109
+ 'no-console': 'warn',
110
+ 'react/no-unknown-property': 'off'
111
+ }
112
+ }
113
+ ]
114
+ },
115
+
116
+ // Prettier 专项配置
117
+ prettier: {
118
+ config: {
119
+ printWidth: 100,
120
+ semi: true
78
121
  }
79
- }
122
+ }
123
+ } as Config;
124
+ ```
125
+
126
+ ### 参数说明 (Arguments)
127
+
128
+ CLI 参数优先级高于配置文件:
129
+
130
+ - `--fix`: 自动修复错误。
131
+ - `--config <path>`: 指定配置文件路径。
132
+ - `--level <level>`: 强制指定项目类型(`js`, `ts`, `frontend`, `nextjs`)。
133
+ - `--cache-dir <dir>`: 指定缓存目录(默认使用 `node_modules/.cache/rhine-lint`)。
134
+
135
+ ## 🔍 项目级别 (Project Levels)
136
+
137
+ Rhine Lint 根据 `level` 参数加载不同的规则集:
138
+
139
+ - **`js`**: 基础 JavaScript 项目。仅包含标准 JS 规则和 Prettier。
140
+ - **`ts`**: TypeScript 项目。包含 TS 类型检查规则、TSDoc 等。
141
+ - **`frontend`** (默认): 前端 React 项目。包含 `ts` 级别所有规则,加上 `React`, `React Hooks`, `JSX` 相关规则。
142
+ - **`nextjs`**: Next.js 项目。包含 `frontend` 级别所有规则,加上 `@next/eslint-plugin-next` 的 Core Web Vitals 等规则。
143
+
144
+ ## 🧠 技术实现与原理 (Implementation Details)
145
+
146
+ Rhine Lint 不仅仅是一个简单的 ESLint 配置包,它是一个 **Linter Orchestrator (检查器编排工具)**。以下是其内部工作流程,帮助理解它是如何保持项目清洁的。
147
+
148
+ ### 1. 动态配置生成 (Dynamic Configuration Generation)
149
+ 传统的 ESLint 配置共享方式通常要求用户在项目中创建一个 `eslint.config.js` 并 `extend` 一个包。Rhine Lint 采用了不同的策略:**(Virtual Configuration)**。
150
+
151
+ 当你运行 `rl` 时:
152
+ 1. **读取配置**: 它首先读取用户的 `rhine-lint.config.ts`。
153
+ 2. **生成临时配置**: 在缓存目录(如 `node_modules/.cache/rhine-lint/`)中,它会基于内存中的逻辑动态生成真实的 `eslint.config.mjs` 和 `prettier.config.mjs` 文件。
154
+ - 这个过程将 `rhine-lint` 内部预设的规则与用户的自定义规则进行合并。
155
+ - 它自动处理了 `tsconfig.json` 的路径解析、Ignore 文件的合并等复杂逻辑。
156
+ 3. **环境隔离**: 这种方式确保了你的项目根目录不会被各种工具的配置文件弄乱。
157
+
158
+ ### 2. 执行流程 (Execution Flow)
159
+ Rhine Lint 实际上是 ESLint 和 Prettier 之上的一个 **Wrapper**:
160
+
161
+ ```mermaid
162
+ graph LR
163
+ User[用户执行 rl] --> CLI[CLI Parser (cac)]
164
+ CLI --> Config[Config Loader]
165
+ Config --> Gen[Config Generator]
166
+ Gen --> Cache[写入临时 Config (.cache/)]
167
+
168
+ Cache --> AsyncRun{并发执行}
169
+ AsyncRun --> ESLint[Spawn: ESLint]
170
+ AsyncRun --> Prettier[Spawn: Prettier]
171
+
172
+ ESLint --> Output[输出结果]
173
+ Prettier --> Output
80
174
  ```
81
175
 
176
+ - **ESLint 执行**: 调用 `eslint` 二进制文件,指向生成的临时配置文件。利用 ESLint v9 的 Flat Config 系统,实现了极快的文件匹配和规则计算。
177
+ - **Prettier 执行**: 调用 `prettier` 二进制文件,同样指向临时配置文件。
178
+ - **结果聚合**: `rl` 会捕获子进程的输出流,进行清洗和格式化,最终以统一的格式呈现给用户。如果任一工具报错,`rl` 也会以非零状态码退出,确保 CI/CD 流程的正确性。
179
+
180
+ ### 3. 技术栈 (Tech Stack)
181
+ - **Runtime**: Node.js (支持 ESM).
182
+ - **ESLint v9**: 全面拥抱 Flat Config,不再支持旧版 `.eslintrc`。
183
+ - **Prettier**: 强固的代码格式化。
184
+ - **TypeScript-ESLint**: 最新的 TS 解析器和规则插件。
185
+ - **Core Plugins**: 集成了 `eslint-plugin-react`, `eslint-plugin-react-hooks`, `@next/eslint-plugin-next`, `eslint-plugin-import-x`, `eslint-plugin-unused-imports`, `@eslint/markdown`, `@eslint/css` 等数十个核心插件。
186
+
187
+ ---
188
+
189
+ ## License
190
+
191
+ MIT © [RhineAI](https://github.com/RhineAI)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhine-lint",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "module": "./dist/index.js",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",