@ai0x0/utils 0.0.30 → 0.0.31

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.
@@ -30,9 +30,12 @@ const plugin = {
30
30
  configs: {
31
31
  recommended: {
32
32
  plugins: { ai0x0: { rules } },
33
- rules: Object.fromEntries(
34
- Object.keys(rules).map((name) => [`ai0x0/${name}`, "error"]),
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") return;
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)) return;
36
+ if (name.length !== 1 || !/^[a-z]$/.test(name)) {
37
+ return;
38
+ }
35
39
 
36
40
  // Skip `_`
37
- if (name === "_") return;
41
+ if (name === "_") {
42
+ return;
43
+ }
38
44
 
39
- // Skip if inside for loop (for (let i = 0..))
40
- let parent = node.parent;
41
- while (parent) {
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
- parent.type === "ForStatement" ||
44
- parent.type === "ForInStatement" ||
45
- parent.type === "ForOfStatement"
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
- parent = parent.parent;
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) continue;
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.30",
3
+ "version": "0.0.31",
4
4
  "description": "AI0x0 utils",
5
5
  "keywords": [
6
6
  "ai0x0"