eslint-plugin-absolute 0.2.0 → 0.2.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.
- package/.absolutejs/eslint.cache.json +49 -0
- package/.absolutejs/prettier.cache.json +49 -0
- package/.absolutejs/tsconfig.tsbuildinfo +1 -0
- package/.claude/settings.local.json +8 -3
- package/dist/index.js +1321 -1419
- package/eslint.config.mjs +107 -0
- package/package.json +10 -8
- package/src/index.ts +15 -15
- package/src/rules/explicit-object-types.ts +42 -40
- package/src/rules/inline-style-limit.ts +56 -54
- package/src/rules/localize-react-props.ts +261 -266
- package/src/rules/max-depth-extended.ts +55 -66
- package/src/rules/max-jsx-nesting.ts +28 -36
- package/src/rules/min-var-length.ts +238 -208
- package/src/rules/no-button-navigation.ts +114 -156
- package/src/rules/no-explicit-return-types.ts +32 -36
- package/src/rules/no-inline-prop-types.ts +30 -30
- package/src/rules/no-multi-style-objects.ts +35 -42
- package/src/rules/no-nested-jsx-return.ts +100 -105
- package/src/rules/no-or-none-component.ts +17 -19
- package/src/rules/no-transition-cssproperties.ts +76 -70
- package/src/rules/no-unnecessary-div.ts +26 -34
- package/src/rules/no-unnecessary-key.ts +41 -75
- package/src/rules/no-useless-function.ts +18 -20
- package/src/rules/seperate-style-files.ts +19 -21
- package/src/rules/sort-exports.ts +252 -248
- package/src/rules/sort-keys-fixable.ts +354 -328
- package/src/rules/spring-naming-convention.ts +104 -89
- package/tsconfig.json +2 -0
|
@@ -7,33 +7,92 @@ type MessageIds =
|
|
|
7
7
|
| "secondMustMatch"
|
|
8
8
|
| "pluralRequired";
|
|
9
9
|
|
|
10
|
+
const SPRINGS_SUFFIX = "Springs";
|
|
11
|
+
|
|
12
|
+
const checkUseSpring = (
|
|
13
|
+
context: TSESLint.RuleContext<MessageIds, Options>,
|
|
14
|
+
firstElem: TSESTree.Identifier,
|
|
15
|
+
secondElem: TSESTree.Identifier
|
|
16
|
+
) => {
|
|
17
|
+
const firstName = firstElem.name;
|
|
18
|
+
const secondName = secondElem.name;
|
|
19
|
+
|
|
20
|
+
if (!firstName.endsWith(SPRINGS_SUFFIX)) {
|
|
21
|
+
context.report({
|
|
22
|
+
messageId: "firstMustEndWithSprings",
|
|
23
|
+
node: firstElem
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const base = firstName.slice(0, -SPRINGS_SUFFIX.length);
|
|
29
|
+
if (!base) {
|
|
30
|
+
context.report({
|
|
31
|
+
messageId: "firstMustHaveBase",
|
|
32
|
+
node: firstElem
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const expectedSecond = `${base}Api`;
|
|
38
|
+
if (secondName !== expectedSecond) {
|
|
39
|
+
context.report({
|
|
40
|
+
data: { expected: expectedSecond },
|
|
41
|
+
messageId: "secondMustMatch",
|
|
42
|
+
node: secondElem
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const checkUseSprings = (
|
|
48
|
+
context: TSESLint.RuleContext<MessageIds, Options>,
|
|
49
|
+
firstElem: TSESTree.Identifier,
|
|
50
|
+
secondElem: TSESTree.Identifier
|
|
51
|
+
) => {
|
|
52
|
+
const firstName = firstElem.name;
|
|
53
|
+
const secondName = secondElem.name;
|
|
54
|
+
|
|
55
|
+
if (!firstName.endsWith(SPRINGS_SUFFIX)) {
|
|
56
|
+
context.report({
|
|
57
|
+
messageId: "firstMustEndWithSprings",
|
|
58
|
+
node: firstElem
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const basePlural = firstName.slice(0, -SPRINGS_SUFFIX.length);
|
|
64
|
+
if (!basePlural) {
|
|
65
|
+
context.report({
|
|
66
|
+
messageId: "firstMustHaveBase",
|
|
67
|
+
node: firstElem
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!basePlural.endsWith("s")) {
|
|
73
|
+
context.report({
|
|
74
|
+
messageId: "pluralRequired",
|
|
75
|
+
node: firstElem
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const expectedSecond = `${basePlural}Api`;
|
|
81
|
+
if (secondName !== expectedSecond) {
|
|
82
|
+
context.report({
|
|
83
|
+
data: { expected: expectedSecond },
|
|
84
|
+
messageId: "secondMustMatch",
|
|
85
|
+
node: secondElem
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
10
90
|
export const springNamingConvention: TSESLint.RuleModule<MessageIds, Options> =
|
|
11
91
|
{
|
|
12
|
-
meta: {
|
|
13
|
-
type: "problem",
|
|
14
|
-
docs: {
|
|
15
|
-
description:
|
|
16
|
-
"Enforce correct naming for useSpring and useSprings hook destructuring"
|
|
17
|
-
},
|
|
18
|
-
schema: [],
|
|
19
|
-
messages: {
|
|
20
|
-
firstMustEndWithSprings:
|
|
21
|
-
"The first variable must end with 'Springs'.",
|
|
22
|
-
firstMustHaveBase:
|
|
23
|
-
"The first variable must have a non-empty name before 'Springs'.",
|
|
24
|
-
secondMustMatch:
|
|
25
|
-
"The second variable must be named '{{expected}}'.",
|
|
26
|
-
pluralRequired:
|
|
27
|
-
"The first variable for useSprings should be plural (ending with 's') before 'Springs'."
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
defaultOptions: [],
|
|
32
|
-
|
|
33
92
|
create(context) {
|
|
34
93
|
return {
|
|
35
94
|
VariableDeclarator(node: TSESTree.VariableDeclarator) {
|
|
36
|
-
const init = node
|
|
95
|
+
const { init } = node;
|
|
37
96
|
|
|
38
97
|
if (
|
|
39
98
|
!init ||
|
|
@@ -52,13 +111,12 @@ export const springNamingConvention: TSESLint.RuleModule<MessageIds, Options> =
|
|
|
52
111
|
return;
|
|
53
112
|
}
|
|
54
113
|
|
|
55
|
-
const elements = node.id
|
|
114
|
+
const { elements } = node.id;
|
|
56
115
|
if (elements.length < 2) {
|
|
57
116
|
return;
|
|
58
117
|
}
|
|
59
118
|
|
|
60
|
-
const firstElem = elements
|
|
61
|
-
const secondElem = elements[1];
|
|
119
|
+
const [firstElem, secondElem] = elements;
|
|
62
120
|
|
|
63
121
|
if (
|
|
64
122
|
!firstElem ||
|
|
@@ -69,77 +127,34 @@ export const springNamingConvention: TSESLint.RuleModule<MessageIds, Options> =
|
|
|
69
127
|
return;
|
|
70
128
|
}
|
|
71
129
|
|
|
72
|
-
const firstName = firstElem.name;
|
|
73
|
-
const secondName = secondElem.name;
|
|
74
|
-
|
|
75
130
|
if (hookName === "useSpring") {
|
|
76
|
-
|
|
77
|
-
context.report({
|
|
78
|
-
node: firstElem,
|
|
79
|
-
messageId: "firstMustEndWithSprings"
|
|
80
|
-
});
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const base = firstName.slice(0, -"Springs".length);
|
|
85
|
-
if (!base) {
|
|
86
|
-
context.report({
|
|
87
|
-
node: firstElem,
|
|
88
|
-
messageId: "firstMustHaveBase"
|
|
89
|
-
});
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const expectedSecond = `${base}Api`;
|
|
94
|
-
if (secondName !== expectedSecond) {
|
|
95
|
-
context.report({
|
|
96
|
-
node: secondElem,
|
|
97
|
-
messageId: "secondMustMatch",
|
|
98
|
-
data: { expected: expectedSecond }
|
|
99
|
-
});
|
|
100
|
-
}
|
|
131
|
+
checkUseSpring(context, firstElem, secondElem);
|
|
101
132
|
return;
|
|
102
133
|
}
|
|
103
134
|
|
|
104
135
|
if (hookName === "useSprings") {
|
|
105
|
-
|
|
106
|
-
context.report({
|
|
107
|
-
node: firstElem,
|
|
108
|
-
messageId: "firstMustEndWithSprings"
|
|
109
|
-
});
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const basePlural = firstName.slice(
|
|
114
|
-
0,
|
|
115
|
-
-"Springs".length
|
|
116
|
-
);
|
|
117
|
-
if (!basePlural) {
|
|
118
|
-
context.report({
|
|
119
|
-
node: firstElem,
|
|
120
|
-
messageId: "firstMustHaveBase"
|
|
121
|
-
});
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (!basePlural.endsWith("s")) {
|
|
126
|
-
context.report({
|
|
127
|
-
node: firstElem,
|
|
128
|
-
messageId: "pluralRequired"
|
|
129
|
-
});
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const expectedSecond = `${basePlural}Api`;
|
|
134
|
-
if (secondName !== expectedSecond) {
|
|
135
|
-
context.report({
|
|
136
|
-
node: secondElem,
|
|
137
|
-
messageId: "secondMustMatch",
|
|
138
|
-
data: { expected: expectedSecond }
|
|
139
|
-
});
|
|
140
|
-
}
|
|
136
|
+
checkUseSprings(context, firstElem, secondElem);
|
|
141
137
|
}
|
|
142
138
|
}
|
|
143
139
|
};
|
|
140
|
+
},
|
|
141
|
+
defaultOptions: [],
|
|
142
|
+
meta: {
|
|
143
|
+
docs: {
|
|
144
|
+
description:
|
|
145
|
+
"Enforce correct naming for useSpring and useSprings hook destructuring"
|
|
146
|
+
},
|
|
147
|
+
messages: {
|
|
148
|
+
firstMustEndWithSprings:
|
|
149
|
+
"The first variable must end with 'Springs'.",
|
|
150
|
+
firstMustHaveBase:
|
|
151
|
+
"The first variable must have a non-empty name before 'Springs'.",
|
|
152
|
+
pluralRequired:
|
|
153
|
+
"The first variable for useSprings should be plural (ending with 's') before 'Springs'.",
|
|
154
|
+
secondMustMatch:
|
|
155
|
+
"The second variable must be named '{{expected}}'."
|
|
156
|
+
},
|
|
157
|
+
schema: [],
|
|
158
|
+
type: "problem"
|
|
144
159
|
}
|
|
145
160
|
};
|