@ai0x0/utils 0.0.30 → 0.0.32
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/eslint-rules/index.js +6 -3
- package/eslint-rules/no-one-letter-vars.js +26 -11
- package/package.json +4 -16
package/eslint-rules/index.js
CHANGED
|
@@ -30,9 +30,12 @@ const plugin = {
|
|
|
30
30
|
configs: {
|
|
31
31
|
recommended: {
|
|
32
32
|
plugins: { ai0x0: { rules } },
|
|
33
|
-
rules:
|
|
34
|
-
Object.
|
|
35
|
-
|
|
33
|
+
rules: {
|
|
34
|
+
...Object.fromEntries(
|
|
35
|
+
Object.keys(rules).map((name) => [`ai0x0/${name}`, "error"]),
|
|
36
|
+
),
|
|
37
|
+
curly: "error",
|
|
38
|
+
},
|
|
36
39
|
},
|
|
37
40
|
},
|
|
38
41
|
};
|
|
@@ -29,24 +29,37 @@ const rule = {
|
|
|
29
29
|
return {
|
|
30
30
|
// --- 变量声名 ---
|
|
31
31
|
VariableDeclarator(node) {
|
|
32
|
-
if (!node.id || node.id.type !== "Identifier")
|
|
32
|
+
if (!node.id || node.id.type !== "Identifier") {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
33
35
|
const name = node.id.name;
|
|
34
|
-
if (name.length !== 1 || !/^[a-z]$/.test(name))
|
|
36
|
+
if (name.length !== 1 || !/^[a-z]$/.test(name)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
35
39
|
|
|
36
40
|
// Skip `_`
|
|
37
|
-
if (name === "_")
|
|
41
|
+
if (name === "_") {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
38
44
|
|
|
39
|
-
// Skip
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
// Skip only the loop variable itself in for...of/for...in (for (const x of arr))
|
|
46
|
+
// NOT single-letter vars declared inside the loop body
|
|
47
|
+
const declParent = node.parent;
|
|
48
|
+
if (declParent && declParent.type === "VariableDeclaration") {
|
|
49
|
+
const declGrandparent = declParent.parent;
|
|
42
50
|
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
declGrandparent &&
|
|
52
|
+
(declGrandparent.type === "ForOfStatement" ||
|
|
53
|
+
declGrandparent.type === "ForInStatement") &&
|
|
54
|
+
declParent.declarations.length === 1 &&
|
|
55
|
+
declParent.declarations[0] === node
|
|
46
56
|
) {
|
|
47
57
|
return;
|
|
48
58
|
}
|
|
49
|
-
|
|
59
|
+
// Also skip the iterator in for (let i = 0; ...)
|
|
60
|
+
if (declGrandparent && declGrandparent.type === "ForStatement") {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
50
63
|
}
|
|
51
64
|
|
|
52
65
|
context.report({
|
|
@@ -85,7 +98,9 @@ const rule = {
|
|
|
85
98
|
|
|
86
99
|
function checkPattern(pattern, ctx) {
|
|
87
100
|
for (const prop of pattern.properties || pattern.elements || []) {
|
|
88
|
-
if (!prop)
|
|
101
|
+
if (!prop) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
89
104
|
const value =
|
|
90
105
|
prop.type === "RestElement" ? prop.argument : prop.value || prop;
|
|
91
106
|
if (value.type === "Identifier") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai0x0/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "AI0x0 utils",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai0x0"
|
|
@@ -20,17 +20,15 @@
|
|
|
20
20
|
"module": "./es/index.js",
|
|
21
21
|
"types": "./lib/index.d.ts",
|
|
22
22
|
"files": [
|
|
23
|
-
"SKILL.md",
|
|
24
23
|
"es",
|
|
24
|
+
"lib",
|
|
25
25
|
"eslint-config",
|
|
26
26
|
"eslint-rules",
|
|
27
|
-
"
|
|
27
|
+
"SKILL.md"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "node scripts/build.mjs",
|
|
31
31
|
"build:watch": "father dev",
|
|
32
|
-
"docs:build": "dumi build",
|
|
33
|
-
"docs:dev": "dumi dev",
|
|
34
32
|
"prepare": "husky install",
|
|
35
33
|
"prepublishOnly": "npm run build",
|
|
36
34
|
"release": "semantic-release",
|
|
@@ -52,34 +50,24 @@
|
|
|
52
50
|
"@commitlint/cli": "^20.5.0",
|
|
53
51
|
"@eslint/eslintrc": "^3.3.5",
|
|
54
52
|
"@eslint/js": "^10.0.1",
|
|
55
|
-
"@testing-library/react": "^16.3.2",
|
|
56
|
-
"@types/react": "^19.2.14",
|
|
57
|
-
"@types/react-dom": "^19.2.3",
|
|
58
53
|
"@typescript-eslint/eslint-plugin": "^8.58.2",
|
|
59
54
|
"@vitest/coverage-v8": "^2.1.9",
|
|
60
|
-
"antd": "^6.3.5",
|
|
61
|
-
"babel-plugin-antd-style": "^1.0.4",
|
|
62
55
|
"clean-package": "^2.2.0",
|
|
63
56
|
"commitlint": "^20.5.0",
|
|
64
57
|
"cross-env": "^10.1.0",
|
|
65
58
|
"dayjs": "^1.11.20",
|
|
66
59
|
"drizzle-orm": "^0.45.2",
|
|
67
60
|
"drizzle-zod": "^0.8.3",
|
|
68
|
-
"dumi": "^2.4.23",
|
|
69
|
-
"dumi-theme-lobehub": "^5.0.0",
|
|
70
61
|
"eslint": "9",
|
|
71
|
-
"eslint-config-next": "^16.2.4",
|
|
72
62
|
"eslint-config-prettier": "^10.1.8",
|
|
73
63
|
"eslint-plugin-prettier": "^5.5.5",
|
|
74
64
|
"father": "^4.6.18",
|
|
75
65
|
"husky": "^9.1.7",
|
|
76
66
|
"lint-staged": "^16.4.0",
|
|
77
|
-
"next": "^16.2.
|
|
67
|
+
"next": "^16.2.6",
|
|
78
68
|
"next-rest-framework": "github:mushan0x0/next-rest-framework#pkg",
|
|
79
69
|
"prettier": "^3.8.3",
|
|
80
70
|
"pretty-quick": "^4.2.2",
|
|
81
|
-
"react": "^19.2.5",
|
|
82
|
-
"react-dom": "^19.2.5",
|
|
83
71
|
"remark-cli": "^12.0.1",
|
|
84
72
|
"tsc-files": "^1.1.4",
|
|
85
73
|
"tsx": "^4.21.0",
|