@cude/lint 0.0.0-stage → 1.0.0
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.
- package/README.md +109 -2
- package/build/chunk-UBESIHBJ.mjs +13 -0
- package/build/cli.d.mts +1 -0
- package/build/cli.d.ts +1 -0
- package/build/cli.js +2 -0
- package/build/cli.mjs +2 -0
- package/build/index.d.mts +18 -0
- package/build/index.d.ts +18 -0
- package/build/index.js +13 -0
- package/build/index.mjs +1 -0
- package/package.json +35 -3
package/README.md
CHANGED
|
@@ -1,3 +1,110 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cude/lint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](<>)
|
|
4
|
+
[](https://eslint.org/)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://nodejs.org/)
|
|
7
|
+
[](<>)
|
|
8
|
+
[](<>)
|
|
9
|
+
[](https://www.npmjs.com/package/@cude/lint)
|
|
10
|
+
[](<>)
|
|
11
|
+
|
|
12
|
+
## 📖 简述
|
|
13
|
+
|
|
14
|
+
`@cude/lint`是面向多项目协作的代码质量与排版规范工具包。它把日常检查和格式化规则集中封装,让新项目和已有项目都能用同一套标准保持代码干净整洁,同时保留按需调整的空间。
|
|
15
|
+
|
|
16
|
+
## 🌟 核心特性
|
|
17
|
+
|
|
18
|
+
- **开箱即用,少写重复配置**:项目不用在每个仓库里从头搭一套检查和排版规则,直接接入就能获得一致的检查体验。
|
|
19
|
+
- **支持本地个性化补充**:项目有自己的特殊目录或规则偏好时,可以在本地配置文件里单独补充或覆盖,不影响整体默认标准。
|
|
20
|
+
- **代码与排版风格统一**:把代码检查和排版规则放在一起管理,减少团队成员之间因为引号、缩进、换行等习惯不同产生的来回修改。
|
|
21
|
+
- **多类常见文件都能管**:除了常见的代码文件,也兼顾配置文件、文档和说明类文件,让整个项目里的文件风格更一致。
|
|
22
|
+
- **跨编辑器与团队规范对齐**:提供统一的编辑器基础规范和忽略清单模板,帮助不同开发者和不同工具看到同一套底线要求。
|
|
23
|
+
- **支持自动整理修复**:发现部分排版或格式问题时可直接自动整理,减少人工逐行修改的成本。
|
|
24
|
+
|
|
25
|
+
## ⚙️ 核心配置说明
|
|
26
|
+
|
|
27
|
+
在 ESLint Flat Config 体系下,每个配置对象(配置块)支持的核心字段及 @cude/lint 中的对应说明如下:
|
|
28
|
+
|
|
29
|
+
- 文件匹配与忽略
|
|
30
|
+
- files:指定该配置块生效的文件路径匹配模式(如 **/\*.{js,jsx,ts,tsx,mjs,cjs,mts,cts}、**/_.json、\**/_.jsonc、**/.vscode/*.json)
|
|
31
|
+
- ignores:指定排除的文件或目录模式;当对象中不含 files 时作为全局忽略生效,与外部配置合并时取并集
|
|
32
|
+
|
|
33
|
+
- 语言与解析器
|
|
34
|
+
- language:指定语言插件提供的语言标识(如 @eslint/json 的 json/json、json/jsonc)
|
|
35
|
+
- languageOptions:配置解析器与语言环境选项,包括 parser、parserOptions、sourceType(如 module、commonjs、script)以及 globals 全局变量声明
|
|
36
|
+
|
|
37
|
+
- 插件与规则
|
|
38
|
+
- plugins:注册配置块内使用的插件对象(如 prettier、react-hooks、json),供 rules 引用
|
|
39
|
+
- rules:定义具体检查规则及级别(off / warn / error 或数字 0 / 1 / 2)与规则参数,后出现的配置块会覆盖同名规则
|
|
40
|
+
|
|
41
|
+
- 处理器与配置元信息
|
|
42
|
+
- processor:用于从非 JS/TS 文件中提取代码片段或处理特殊文件内容的处理器
|
|
43
|
+
- settings:为多个规则提供共享上下文设置
|
|
44
|
+
- linterOptions:控制报告行为,如 noInlineConfig 与 reportUnusedDisableDirectives
|
|
45
|
+
- name:为配置块命名,方便调试或排查配置来源
|
|
46
|
+
|
|
47
|
+
## 📦 内置规则
|
|
48
|
+
|
|
49
|
+
@cude/lint 的 baseConfig 默认内置了以下规则与规范(外部项目无需重复配置即可直接生效):
|
|
50
|
+
|
|
51
|
+
- 基础语法与代码质量
|
|
52
|
+
- 启用 JS 推荐规则(@eslint/js recommended)与 TypeScript 推荐规则(typescript-eslint recommended)
|
|
53
|
+
- .cjs 文件自动按 CommonJS 解析(sourceType: 'commonjs')
|
|
54
|
+
- 未使用变量(@typescript-eslint/no-unused-vars)设为 warn,支持以 _ 开头的参数或变量名跳过告警
|
|
55
|
+
- 显式 any(@typescript-eslint/no-explicit-any)设为 warn
|
|
56
|
+
|
|
57
|
+
- React 与 Hooks 规范
|
|
58
|
+
- 针对 .jsx / .tsx 启用 eslint-plugin-react-hooks 推荐规则,检查 Hooks 调用规范与依赖项
|
|
59
|
+
|
|
60
|
+
- 代码格式化
|
|
61
|
+
- 内置 prettierConfig(100 列宽、2 空格缩进、单引号、尾随逗号、行尾分号、LF 换行等)并通过 prettier/prettier 以 warn 级别检查与修复
|
|
62
|
+
- 末尾挂载 eslint-config-prettier,自动关闭与 Prettier 冲突的格式化规则
|
|
63
|
+
|
|
64
|
+
- 多文件类型校验
|
|
65
|
+
- **/*.json:启用 @eslint/json json/json 推荐规则,并关闭与 JSON 不兼容的 no-irregular-whitespace
|
|
66
|
+
- **/_.jsonc 与 \**/.vscode/_.json:启用 json/jsonc 推荐规则
|
|
67
|
+
- Markdown(@eslint/markdown)与 YAML(eslint-plugin-yml):启用各自推荐预设进行文档与配置检查
|
|
68
|
+
|
|
69
|
+
- 全局忽略与工程规范导出
|
|
70
|
+
- 默认忽略 node_modules/**、.turbo/**、.vscode/**、coverage/**、dist/**、.prettierrc.* 等目录或文件
|
|
71
|
+
- 同步导出 prettierConfig、prettierIgnorePatterns 与 editorConfigContent,方便工作区保持统一规范
|
|
72
|
+
|
|
73
|
+
## 🚀 使用指南
|
|
74
|
+
|
|
75
|
+
1. 安装依赖
|
|
76
|
+
在项目中安装 @cude/lint(本地多包协作场景通常通过工作区依赖引入):
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pnpm add -D @cude/lint
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
2. 在 package.json 中添加命令
|
|
83
|
+
在子项目的 package.json 中配置检查与自动修复脚本:
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"scripts": {
|
|
88
|
+
"lint": "cudelint .",
|
|
89
|
+
"lint:fix": "cudelint . --fix"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
3. 运行检查与修复
|
|
95
|
+
|
|
96
|
+
- 日常检查:在项目目录下执行 pnpm run lint,查看是否存在需要处理的问题。
|
|
97
|
+
- 一键整理:需要自动修复可处理的问题时,执行 pnpm run lint:fix。
|
|
98
|
+
|
|
99
|
+
4. 按需添加项目专属配置(可选)
|
|
100
|
+
如果当前项目有需要单独忽略的目录或额外规则,可在项目根目录创建 eslint.config.mjs,只写本项目特有的调整即可,其余通用部分会自动合并生效:
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
import {defineConfig} from 'eslint/config';
|
|
104
|
+
|
|
105
|
+
export default defineConfig([
|
|
106
|
+
{
|
|
107
|
+
ignores: ['icons/**'],
|
|
108
|
+
},
|
|
109
|
+
]);
|
|
110
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import t from"eslint-plugin-prettier";import i from"eslint-config-prettier";import o from"@eslint/js";import s from"typescript-eslint";import n from"eslint-plugin-react-hooks";import e from"@eslint/json";import l from"@eslint/markdown";import a from"eslint-plugin-yml";var m={printWidth:100,tabWidth:2,useTabs:!1,semi:!0,singleQuote:!0,trailingComma:"all",bracketSpacing:!1,arrowParens:"avoid",endOfLine:"lf"},r=["node_modules/**",".turbo/**",".vscode/**","coverage/**","dist/**","**/pnpm-lock.yaml","**/npm-lock.json","**/*.min.*"],_=`root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
charset = utf-8
|
|
5
|
+
end_of_line = lf
|
|
6
|
+
indent_style = space
|
|
7
|
+
indent_size = 2
|
|
8
|
+
insert_final_newline = true
|
|
9
|
+
trim_trailing_whitespace = true
|
|
10
|
+
|
|
11
|
+
[*.md]
|
|
12
|
+
trim_trailing_whitespace = false
|
|
13
|
+
`,w=[{ignores:[...r,".prettierrc.*"]},o.configs.recommended,...s.configs.recommended,{files:["**/*.cjs"],languageOptions:{sourceType:"commonjs"}},{files:["**/*.{js,ts,tsx,mjs,cjs,mts,cts}"],plugins:{prettier:t},rules:{"@typescript-eslint/no-unused-vars":["warn",{argsIgnorePattern:"^_",varsIgnorePattern:"^_"}],"@typescript-eslint/no-explicit-any":"warn","prettier/prettier":["warn",m]}},{files:["**/*.{jsx,tsx}"],plugins:{"react-hooks":n},rules:{...n.configs.recommended?.rules??{}}},{files:["**/*.json"],ignores:[...r],plugins:{json:e},language:"json/json",rules:{...e.configs.recommended.rules,"no-irregular-whitespace":"off"}},{files:["**/*.jsonc"],ignores:[...r],plugins:{json:e},language:"json/jsonc",rules:{...e.configs.recommended.rules,"no-irregular-whitespace":"off"}},...l.configs.recommended,...a.configs["flat/recommended"],i];export{m as a,r as b,_ as c,w as d};
|
package/build/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/build/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/build/cli.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";var v=Object.create;var u=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var I=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of E(t))!N.call(e,o)&&o!==r&&u(e,o,{get:()=>t[o],enumerable:!(i=k(t,o))||i.enumerable});return e};var n=(e,t,r)=>(r=e!=null?v(F(e)):{},I(t||!e||!e.__esModule?u(r,"default",{value:e,enumerable:!0}):r,e));var _=n(require("fs")),L=n(require("path")),P=require("url"),m=require("eslint");var d=n(require("eslint-plugin-prettier")),C=n(require("eslint-config-prettier")),w=n(require("@eslint/js")),j=n(require("typescript-eslint")),c=n(require("eslint-plugin-react-hooks")),s=n(require("@eslint/json")),h=n(require("@eslint/markdown")),x=n(require("eslint-plugin-yml")),A={printWidth:100,tabWidth:2,useTabs:!1,semi:!0,singleQuote:!0,trailingComma:"all",bracketSpacing:!1,arrowParens:"avoid",endOfLine:"lf"},f=["node_modules/**",".turbo/**",".vscode/**","coverage/**","dist/**","**/pnpm-lock.yaml","**/npm-lock.json","**/*.min.*"];var y=[{ignores:[...f,".prettierrc.*"]},w.default.configs.recommended,...j.default.configs.recommended,{files:["**/*.cjs"],languageOptions:{sourceType:"commonjs"}},{files:["**/*.{js,ts,tsx,mjs,cjs,mts,cts}"],plugins:{prettier:d.default},rules:{"@typescript-eslint/no-unused-vars":["warn",{argsIgnorePattern:"^_",varsIgnorePattern:"^_"}],"@typescript-eslint/no-explicit-any":"warn","prettier/prettier":["warn",A]}},{files:["**/*.{jsx,tsx}"],plugins:{"react-hooks":c.default},rules:{...c.default.configs.recommended?.rules??{}}},{files:["**/*.json"],ignores:[...f],plugins:{json:s.default},language:"json/json",rules:{...s.default.configs.recommended.rules,"no-irregular-whitespace":"off"}},{files:["**/*.jsonc"],ignores:[...f],plugins:{json:s.default},language:"json/jsonc",rules:{...s.default.configs.recommended.rules,"no-irregular-whitespace":"off"}},...h.default.configs.recommended,...x.default.configs["flat/recommended"],C.default];var S=["eslint.config.mjs","eslint.config.js","eslint.config.cjs","eslint.config.mts","eslint.config.cts","eslint.config.ts"];async function T(e){for(let t of S){let r=L.default.join(e,t);if(_.default.existsSync(r)){let i=await import((0,P.pathToFileURL)(r).href),o=i.default??i;return Array.isArray(o)?o:[o]}}return[]}async function O(){let e=process.cwd(),t=process.argv.slice(2),r=t.includes("--fix"),i=t.filter(a=>!a.startsWith("-")),o=await T(e),b=[...y,...o],g=new m.ESLint({cwd:e,fix:r,overrideConfigFile:!0,overrideConfig:b}),l=await g.lintFiles(i.length>0?i:["."]);r&&await m.ESLint.outputFixes(l);let p=await(await g.loadFormatter("stylish")).format(l);p&&console.log(p),l.some(a=>a.errorCount>0||a.fatalErrorCount>0)&&(process.exitCode=1)}O().catch(e=>{console.error(e),process.exitCode=1});
|
package/build/cli.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{d as f}from"./chunk-UBESIHBJ.mjs";import g from"fs";import p from"path";import{pathToFileURL as u}from"url";import{ESLint as l}from"eslint";var d=["eslint.config.mjs","eslint.config.js","eslint.config.cjs","eslint.config.mts","eslint.config.cts","eslint.config.ts"];async function C(t){for(let n of d){let o=p.join(t,n);if(g.existsSync(o)){let i=await import(u(o).href),r=i.default??i;return Array.isArray(r)?r:[r]}}return[]}async function h(){let t=process.cwd(),n=process.argv.slice(2),o=n.includes("--fix"),i=n.filter(s=>!s.startsWith("-")),r=await C(t),m=[...f,...r],c=new l({cwd:t,fix:o,overrideConfigFile:!0,overrideConfig:m}),e=await c.lintFiles(i.length>0?i:["."]);o&&await l.outputFixes(e);let a=await(await c.loadFormatter("stylish")).format(e);a&&console.log(a),e.some(s=>s.errorCount>0||s.fatalErrorCount>0)&&(process.exitCode=1)}h().catch(t=>{console.error(t),process.exitCode=1});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Linter } from 'eslint';
|
|
2
|
+
import { Config } from 'prettier';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 代码格式化规则
|
|
6
|
+
*/
|
|
7
|
+
declare const prettierConfig: Config;
|
|
8
|
+
/**
|
|
9
|
+
* 代码格式化忽略目录
|
|
10
|
+
*/
|
|
11
|
+
declare const prettierIgnorePatterns: string[];
|
|
12
|
+
/**
|
|
13
|
+
* 代码编辑器统一规范
|
|
14
|
+
*/
|
|
15
|
+
declare const editorConfigContent = "root = true\n\n[*]\ncharset = utf-8\nend_of_line = lf\nindent_style = space\nindent_size = 2\ninsert_final_newline = true\ntrim_trailing_whitespace = true\n\n[*.md]\ntrim_trailing_whitespace = false\n";
|
|
16
|
+
declare const baseConfig: Linter.Config[];
|
|
17
|
+
|
|
18
|
+
export { baseConfig, editorConfigContent, prettierConfig, prettierIgnorePatterns };
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Linter } from 'eslint';
|
|
2
|
+
import { Config } from 'prettier';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 代码格式化规则
|
|
6
|
+
*/
|
|
7
|
+
declare const prettierConfig: Config;
|
|
8
|
+
/**
|
|
9
|
+
* 代码格式化忽略目录
|
|
10
|
+
*/
|
|
11
|
+
declare const prettierIgnorePatterns: string[];
|
|
12
|
+
/**
|
|
13
|
+
* 代码编辑器统一规范
|
|
14
|
+
*/
|
|
15
|
+
declare const editorConfigContent = "root = true\n\n[*]\ncharset = utf-8\nend_of_line = lf\nindent_style = space\nindent_size = 2\ninsert_final_newline = true\ntrim_trailing_whitespace = true\n\n[*.md]\ntrim_trailing_whitespace = false\n";
|
|
16
|
+
declare const baseConfig: Linter.Config[];
|
|
17
|
+
|
|
18
|
+
export { baseConfig, editorConfigContent, prettierConfig, prettierIgnorePatterns };
|
package/build/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";var _=Object.create;var s=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var k=(e,r)=>{for(var n in r)s(e,n,{get:r[n],enumerable:!0})},g=(e,r,n,m)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of y(r))!h.call(e,i)&&i!==n&&s(e,i,{get:()=>r[i],enumerable:!(m=w(r,i))||m.enumerable});return e};var t=(e,r,n)=>(n=e!=null?_(P(e)):{},g(r||!e||!e.__esModule?s(n,"default",{value:e,enumerable:!0}):n,e)),x=e=>g(s({},"__esModule",{value:!0}),e);var v={};k(v,{baseConfig:()=>L,editorConfigContent:()=>b,prettierConfig:()=>C,prettierIgnorePatterns:()=>l});module.exports=x(v);var f=t(require("eslint-plugin-prettier")),p=t(require("eslint-config-prettier")),c=t(require("@eslint/js")),u=t(require("typescript-eslint")),a=t(require("eslint-plugin-react-hooks")),o=t(require("@eslint/json")),d=t(require("@eslint/markdown")),j=t(require("eslint-plugin-yml")),C={printWidth:100,tabWidth:2,useTabs:!1,semi:!0,singleQuote:!0,trailingComma:"all",bracketSpacing:!1,arrowParens:"avoid",endOfLine:"lf"},l=["node_modules/**",".turbo/**",".vscode/**","coverage/**","dist/**","**/pnpm-lock.yaml","**/npm-lock.json","**/*.min.*"],b=`root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
charset = utf-8
|
|
5
|
+
end_of_line = lf
|
|
6
|
+
indent_style = space
|
|
7
|
+
indent_size = 2
|
|
8
|
+
insert_final_newline = true
|
|
9
|
+
trim_trailing_whitespace = true
|
|
10
|
+
|
|
11
|
+
[*.md]
|
|
12
|
+
trim_trailing_whitespace = false
|
|
13
|
+
`,L=[{ignores:[...l,".prettierrc.*"]},c.default.configs.recommended,...u.default.configs.recommended,{files:["**/*.cjs"],languageOptions:{sourceType:"commonjs"}},{files:["**/*.{js,ts,tsx,mjs,cjs,mts,cts}"],plugins:{prettier:f.default},rules:{"@typescript-eslint/no-unused-vars":["warn",{argsIgnorePattern:"^_",varsIgnorePattern:"^_"}],"@typescript-eslint/no-explicit-any":"warn","prettier/prettier":["warn",C]}},{files:["**/*.{jsx,tsx}"],plugins:{"react-hooks":a.default},rules:{...a.default.configs.recommended?.rules??{}}},{files:["**/*.json"],ignores:[...l],plugins:{json:o.default},language:"json/json",rules:{...o.default.configs.recommended.rules,"no-irregular-whitespace":"off"}},{files:["**/*.jsonc"],ignores:[...l],plugins:{json:o.default},language:"json/jsonc",rules:{...o.default.configs.recommended.rules,"no-irregular-whitespace":"off"}},...d.default.configs.recommended,...j.default.configs["flat/recommended"],p.default];0&&(module.exports={baseConfig,editorConfigContent,prettierConfig,prettierIgnorePatterns});
|
package/build/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d}from"./chunk-UBESIHBJ.mjs";export{d as baseConfig,c as editorConfigContent,a as prettierConfig,b as prettierIgnorePatterns};
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cude/lint",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "./build/index.js",
|
|
5
|
+
"types": "./build/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./build/index.d.ts",
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./build/index.d.mts",
|
|
11
|
+
"default": "./build/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./build/index.d.ts",
|
|
15
|
+
"default": "./build/index.js"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"directory": "dist",
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"bin": {
|
|
24
|
+
"cudelint": "./build/cli.js"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"prettier": "^3.0.0",
|
|
28
|
+
"eslint": "^10.0.0",
|
|
29
|
+
"@eslint/js": "^10.0.0",
|
|
30
|
+
"@eslint/json": "^2.1.2",
|
|
31
|
+
"@eslint/markdown": "^9.0.0",
|
|
32
|
+
"eslint-plugin-yml": "^3.0.0",
|
|
33
|
+
"typescript-eslint": "^8.70.0",
|
|
34
|
+
"eslint-plugin-react-hooks": "^7.0.0",
|
|
35
|
+
"eslint-plugin-prettier": "^5.5.0",
|
|
36
|
+
"eslint-config-prettier": "^10.0.0"
|
|
37
|
+
}
|
|
6
38
|
}
|