@futdevpro/dynamo-eslint 1.15.28 → 1.20.3
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 +13 -16
- package/__documentations/2026-08-22-angular-20-phase2-release.md +83 -0
- package/build/configs/base.d.ts +8 -9
- package/build/configs/base.d.ts.map +1 -1
- package/build/configs/base.js +149 -150
- package/build/configs/base.js.map +1 -1
- package/build/configs/fsm.d.ts +1 -1
- package/build/configs/fsm.js +7 -7
- package/build/configs/ngx-package.d.ts +1 -1
- package/build/configs/ngx-package.js +7 -7
- package/build/configs/ngx.d.ts +2 -4
- package/build/configs/ngx.d.ts.map +1 -1
- package/build/configs/ngx.js +88 -91
- package/build/configs/ngx.js.map +1 -1
- package/build/configs/nts-package.d.ts +1 -1
- package/build/configs/nts-package.js +17 -17
- package/build/configs/nts.d.ts +1 -1
- package/build/configs/nts.js +31 -31
- package/build/index.d.ts +1 -1
- package/build/index.js +2 -2
- package/build/plugin/index.d.ts +52 -52
- package/build/plugin/index.js +80 -80
- package/build/plugin/rules/angular/angular-for-track-logic.d.ts +7 -7
- package/build/plugin/rules/angular/angular-for-track-logic.js +81 -81
- package/build/plugin/rules/angular/effect-signal-loop.d.ts +9 -9
- package/build/plugin/rules/angular/effect-signal-loop.js +112 -112
- package/build/plugin/rules/angular/no-async-ngoninit.d.ts +8 -8
- package/build/plugin/rules/angular/no-async-ngoninit.js +42 -42
- package/build/plugin/rules/angular/no-component-direct-api.d.ts +9 -9
- package/build/plugin/rules/angular/no-component-direct-api.js +75 -75
- package/build/plugin/rules/angular/no-method-call-in-template.d.ts +8 -8
- package/build/plugin/rules/angular/no-method-call-in-template.js +79 -79
- package/build/plugin/rules/angular/no-ngfor-directive.d.ts +7 -7
- package/build/plugin/rules/angular/no-ngfor-directive.js +59 -59
- package/build/plugin/rules/angular/no-ngif-directive.d.ts +7 -7
- package/build/plugin/rules/angular/no-ngif-directive.js +59 -59
- package/build/plugin/rules/explicit-types.d.ts +3 -3
- package/build/plugin/rules/explicit-types.js +178 -178
- package/build/plugin/rules/import/import-order.d.ts +3 -3
- package/build/plugin/rules/import/import-order.js +154 -154
- package/build/plugin/rules/import/no-import-type.d.ts +3 -3
- package/build/plugin/rules/import/no-import-type.js +45 -45
- package/build/plugin/rules/import/no-js-import.d.ts +3 -3
- package/build/plugin/rules/import/no-js-import.js +40 -40
- package/build/plugin/rules/naming-patterns.d.ts +7 -7
- package/build/plugin/rules/naming-patterns.js +366 -366
- package/build/plugin/rules/no-getter-logic.d.ts +3 -3
- package/build/plugin/rules/no-getter-logic.js +194 -194
- package/build/plugin/rules/no-getter-logic.js.map +1 -1
- package/build/plugin/rules/prefer-enum-over-string-union.d.ts +3 -3
- package/build/plugin/rules/prefer-enum-over-string-union.js +289 -289
- package/build/plugin/rules/prefer-enum-over-string-union.js.map +1 -1
- package/build/plugin/rules/prefer-interface-over-duplicate-types.d.ts +3 -3
- package/build/plugin/rules/prefer-interface-over-duplicate-types.js +264 -264
- package/build/plugin/rules/prefer-interface-over-duplicate-types.js.map +1 -1
- package/build/plugin/rules/require-jsdoc-description.d.ts +3 -3
- package/build/plugin/rules/require-jsdoc-description.js +496 -496
- package/build/plugin/rules/require-jsdoc-description.js.map +1 -1
- package/build/plugin/rules/require-test-description-prefix.d.ts +3 -3
- package/build/plugin/rules/require-test-description-prefix.js +135 -135
- package/build/plugin/rules/ts/data-model-extends.d.ts +8 -8
- package/build/plugin/rules/ts/data-model-extends.js +94 -94
- package/build/plugin/rules/ts/no-any-type.d.ts +8 -8
- package/build/plugin/rules/ts/no-any-type.js +36 -36
- package/build/plugin/rules/ts/no-as-cast.d.ts +8 -8
- package/build/plugin/rules/ts/no-as-cast.js +49 -49
- package/build/plugin/rules/ts/no-dynamic-imports.d.ts +8 -8
- package/build/plugin/rules/ts/no-dynamic-imports.js +50 -50
- package/build/plugin/rules/ts/no-native-browser-dialogs.d.ts +8 -8
- package/build/plugin/rules/ts/no-native-browser-dialogs.js +78 -78
- package/build/plugin/rules/ts/no-plain-function-export.d.ts +9 -9
- package/build/plugin/rules/ts/no-plain-function-export.js +69 -69
- package/build/plugin/rules/ts/one-export-per-file.d.ts +8 -8
- package/build/plugin/rules/ts/one-export-per-file.js +73 -73
- package/build/scripts/dynamo-fix.d.ts +26 -26
- package/build/scripts/dynamo-fix.js +146 -146
- package/build/scripts/dynamo-fix.js.map +1 -1
- package/build/scripts/eslintrc-audit.d.ts +26 -26
- package/build/scripts/eslintrc-audit.js +100 -100
- package/build/scripts/fix-return-types.d.ts +74 -74
- package/build/scripts/fix-return-types.d.ts.map +1 -1
- package/build/scripts/fix-return-types.js +226 -226
- package/build/scripts/fix-return-types.js.map +1 -1
- package/build/scripts/validate-imports.d.ts +26 -26
- package/build/scripts/validate-imports.js +170 -157
- package/build/scripts/validate-imports.js.map +1 -1
- package/build/scripts/validate-naming.d.ts +26 -26
- package/build/scripts/validate-naming.js +170 -157
- package/build/scripts/validate-naming.js.map +1 -1
- package/eslint.config.js +1 -1
- package/package.json +104 -105
- package/pnpm-workspace.yaml +2 -0
- package/samples/package.json.example +5 -9
- package/src/configs/angular20-compatibility.spec.ts +73 -0
- package/src/configs/base.ts +3 -4
- package/src/configs/ngx.ts +7 -10
- package/src/plugin/rules/no-getter-logic.ts +1 -1
- package/src/plugin/rules/prefer-enum-over-string-union.spec.ts +9 -9
- package/src/plugin/rules/prefer-enum-over-string-union.ts +7 -8
- package/src/plugin/rules/prefer-interface-over-duplicate-types.spec.ts +22 -22
- package/src/plugin/rules/prefer-interface-over-duplicate-types.ts +2 -2
- package/src/plugin/rules/require-jsdoc-description.spec.ts +2 -2
- package/src/plugin/rules/require-jsdoc-description.ts +7 -7
- package/src/scripts/dynamo-fix.ts +1 -1
- package/src/scripts/fix-return-types.ts +4 -3
- package/src/scripts/validate-imports.ts +29 -15
- package/src/scripts/validate-naming.ts +29 -20
- package/src/scripts/validator-cli.integration.spec.ts +11 -8
|
@@ -1,290 +1,290 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const rule = {
|
|
4
|
-
meta: {
|
|
5
|
-
type: 'suggestion',
|
|
6
|
-
docs: {
|
|
7
|
-
description: 'Suggest using enums instead of union types of string literals',
|
|
8
|
-
recommended: true,
|
|
9
|
-
},
|
|
10
|
-
schema: [
|
|
11
|
-
{
|
|
12
|
-
type: 'object',
|
|
13
|
-
properties: {
|
|
14
|
-
minValues: {
|
|
15
|
-
type: 'number',
|
|
16
|
-
minimum: 2,
|
|
17
|
-
default: 3,
|
|
18
|
-
},
|
|
19
|
-
allowTypeAliases: {
|
|
20
|
-
type: 'boolean',
|
|
21
|
-
default: false,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
additionalProperties: false,
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
messages: {
|
|
28
|
-
preferEnum: 'Consider using an enum instead of a union type of {{count}} string literals.',
|
|
29
|
-
},
|
|
30
|
-
fixable: 'code',
|
|
31
|
-
},
|
|
32
|
-
create(context) {
|
|
33
|
-
const options = context.options[0] || {};
|
|
34
|
-
const minValues = options.minValues || 3;
|
|
35
|
-
const allowTypeAliases = options.allowTypeAliases || false;
|
|
36
|
-
/**
|
|
37
|
-
* Check if a union type is composed solely of string literals
|
|
38
|
-
*/
|
|
39
|
-
function isStringLiteralUnion(node) {
|
|
40
|
-
if (node.type !== 'TSUnionType') {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
if (!node.types || !Array.isArray(node.types)) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return node.types.every((type) => type.type === 'TSLiteralType' &&
|
|
47
|
-
typeof type.literal?.value === 'string');
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Check if a property is an Angular component input
|
|
51
|
-
*/
|
|
52
|
-
function isAngularInput(node) {
|
|
53
|
-
try {
|
|
54
|
-
// Check for @Input() decorator (old style)
|
|
55
|
-
if (node.decorators && Array.isArray(node.decorators)) {
|
|
56
|
-
const hasInputDecorator = node.decorators.some((decorator) => {
|
|
57
|
-
const expression = decorator.expression;
|
|
58
|
-
return expression?.type === 'CallExpression' &&
|
|
59
|
-
expression.callee?.name === 'Input';
|
|
60
|
-
});
|
|
61
|
-
if (hasInputDecorator) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// Check for input() or input.required() signal (new style)
|
|
66
|
-
if (node.value?.type === 'CallExpression') {
|
|
67
|
-
const callee = node.value.callee;
|
|
68
|
-
// Direct call: input()
|
|
69
|
-
if (callee?.name === 'input') {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
// Member call: input.required()
|
|
73
|
-
if (callee?.object?.name === 'input' && callee?.property?.name === 'required') {
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
console.error('[prefer-enum-over-string-union] Error checking Angular input:', error);
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Check if a union type meets the minimum threshold
|
|
86
|
-
*/
|
|
87
|
-
function meetsThreshold(node) {
|
|
88
|
-
if (node.type !== 'TSUnionType' || !node.types) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
const stringLiteralCount = node.types.filter((type) => type.type === 'TSLiteralType' &&
|
|
92
|
-
typeof type.literal?.value === 'string').length;
|
|
93
|
-
return stringLiteralCount >= minValues;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Generate enum name suggestion based on context
|
|
97
|
-
*/
|
|
98
|
-
function generateEnumName(node, parent) {
|
|
99
|
-
try {
|
|
100
|
-
// For type aliases, use the type name
|
|
101
|
-
if (parent?.type === 'TSTypeAliasDeclaration' && parent.id?.name) {
|
|
102
|
-
return parent.id.name;
|
|
103
|
-
}
|
|
104
|
-
// For properties, use property name + "Enum"
|
|
105
|
-
if (node.type === 'TSPropertySignature' && node.key?.name) {
|
|
106
|
-
return `${node.key.name.charAt(0).toUpperCase() + node.key.name.slice(1)}Enum`;
|
|
107
|
-
}
|
|
108
|
-
// For class properties, use property name + "Enum"
|
|
109
|
-
if (parent?.type === 'PropertyDefinition' && parent.key?.name) {
|
|
110
|
-
return `${parent.key.name.charAt(0).toUpperCase() + parent.key.name.slice(1)}Enum`;
|
|
111
|
-
}
|
|
112
|
-
// Default fallback
|
|
113
|
-
return 'StatusEnum';
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
console.error('[prefer-enum-over-string-union] Error generating enum name:', error);
|
|
117
|
-
return 'StatusEnum';
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Generate enum values from string literals
|
|
122
|
-
*/
|
|
123
|
-
function generateEnumValues(node) {
|
|
124
|
-
if (node.type !== 'TSUnionType' || !node.types) {
|
|
125
|
-
return [];
|
|
126
|
-
}
|
|
127
|
-
return node.types
|
|
128
|
-
.filter((type) => type.type === 'TSLiteralType' &&
|
|
129
|
-
typeof type.literal?.value === 'string')
|
|
130
|
-
.map((type) => {
|
|
131
|
-
const value = type.literal.value;
|
|
132
|
-
// Convert to PascalCase for enum key
|
|
133
|
-
return value
|
|
134
|
-
.split(/[-_\s]+/)
|
|
135
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
136
|
-
.join('');
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Report violation with enum suggestion
|
|
141
|
-
*/
|
|
142
|
-
function reportViolation(node, parent, unionNode) {
|
|
143
|
-
const stringLiteralCount = unionNode.types.filter((type) => type.type === 'TSLiteralType' &&
|
|
144
|
-
typeof type.literal?.value === 'string').length;
|
|
145
|
-
const enumName = generateEnumName(node, parent);
|
|
146
|
-
const enumValues = generateEnumValues(unionNode);
|
|
147
|
-
context.report({
|
|
148
|
-
node: unionNode,
|
|
149
|
-
messageId: 'preferEnum',
|
|
150
|
-
data: {
|
|
151
|
-
count: stringLiteralCount.toString(),
|
|
152
|
-
},
|
|
153
|
-
fix(fixer) {
|
|
154
|
-
try {
|
|
155
|
-
const enumDeclaration = `enum ${enumName} {\n ${enumValues.map((key, index) => {
|
|
156
|
-
const value = unionNode.types[index].literal.value;
|
|
157
|
-
return `${key} = '${value}'`;
|
|
158
|
-
}).join(',\n ')}\n}`;
|
|
159
|
-
// For type aliases, replace the entire declaration
|
|
160
|
-
if (parent?.type === 'TSTypeAliasDeclaration') {
|
|
161
|
-
const typeText = context.sourceCode.getText(parent);
|
|
162
|
-
const newText = typeText.replace(/=.*/, `= ${enumName};`);
|
|
163
|
-
return fixer.replaceText(parent, newText);
|
|
164
|
-
}
|
|
165
|
-
// For other cases, suggest enum creation (no auto-fix for now)
|
|
166
|
-
return null;
|
|
167
|
-
}
|
|
168
|
-
catch (fixError) {
|
|
169
|
-
console.error('[prefer-enum-over-string-union] Error in fix function:', fixError);
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
return {
|
|
176
|
-
// Type aliases
|
|
177
|
-
TSTypeAliasDeclaration(node
|
|
178
|
-
try {
|
|
179
|
-
if (allowTypeAliases) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
if (isStringLiteralUnion(node.typeAnnotation) && meetsThreshold(node.typeAnnotation)) {
|
|
183
|
-
reportViolation(node.typeAnnotation, node, node.typeAnnotation);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
catch (error) {
|
|
187
|
-
console.error('[prefer-enum-over-string-union] Error in TSTypeAliasDeclaration visitor:', error);
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
// Interface/type properties
|
|
191
|
-
TSPropertySignature(node
|
|
192
|
-
try {
|
|
193
|
-
if (isAngularInput(node)) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
if (node.typeAnnotation &&
|
|
197
|
-
isStringLiteralUnion(node.typeAnnotation.typeAnnotation) &&
|
|
198
|
-
meetsThreshold(node.typeAnnotation.typeAnnotation)) {
|
|
199
|
-
reportViolation(node, node.parent, node.typeAnnotation.typeAnnotation);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
console.error('[prefer-enum-over-string-union] Error in TSPropertySignature visitor:', error);
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
// Class properties
|
|
207
|
-
PropertyDefinition(node
|
|
208
|
-
try {
|
|
209
|
-
if (isAngularInput(node)) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
if (node.typeAnnotation &&
|
|
213
|
-
isStringLiteralUnion(node.typeAnnotation.typeAnnotation) &&
|
|
214
|
-
meetsThreshold(node.typeAnnotation.typeAnnotation)) {
|
|
215
|
-
reportViolation(node, node.parent, node.typeAnnotation.typeAnnotation);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
console.error('[prefer-enum-over-string-union] Error in PropertyDefinition visitor:', error);
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
// Function parameters
|
|
223
|
-
FunctionDeclaration(node
|
|
224
|
-
try {
|
|
225
|
-
if (node.params && Array.isArray(node.params)) {
|
|
226
|
-
node.params.forEach((param) => {
|
|
227
|
-
if (param.typeAnnotation &&
|
|
228
|
-
isStringLiteralUnion(param.typeAnnotation.typeAnnotation) &&
|
|
229
|
-
meetsThreshold(param.typeAnnotation.typeAnnotation)) {
|
|
230
|
-
reportViolation(param, node, param.typeAnnotation.typeAnnotation);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
catch (error) {
|
|
236
|
-
console.error('[prefer-enum-over-string-union] Error in FunctionDeclaration visitor:', error);
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
// Arrow function parameters
|
|
240
|
-
ArrowFunctionExpression(node
|
|
241
|
-
try {
|
|
242
|
-
if (node.params && Array.isArray(node.params)) {
|
|
243
|
-
node.params.forEach((param) => {
|
|
244
|
-
if (param.typeAnnotation &&
|
|
245
|
-
isStringLiteralUnion(param.typeAnnotation.typeAnnotation) &&
|
|
246
|
-
meetsThreshold(param.typeAnnotation.typeAnnotation)) {
|
|
247
|
-
reportViolation(param, node, param.typeAnnotation.typeAnnotation);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
catch (error) {
|
|
253
|
-
console.error('[prefer-enum-over-string-union] Error in ArrowFunctionExpression visitor:', error);
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
// Variable declarations
|
|
257
|
-
VariableDeclarator(node
|
|
258
|
-
try {
|
|
259
|
-
if (node.typeAnnotation &&
|
|
260
|
-
isStringLiteralUnion(node.typeAnnotation.typeAnnotation) &&
|
|
261
|
-
meetsThreshold(node.typeAnnotation.typeAnnotation)) {
|
|
262
|
-
reportViolation(node, node.parent, node.typeAnnotation.typeAnnotation);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
catch (error) {
|
|
266
|
-
console.error('[prefer-enum-over-string-union] Error in VariableDeclarator visitor:', error);
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
// Method signatures
|
|
270
|
-
TSMethodSignature(node
|
|
271
|
-
try {
|
|
272
|
-
if (node.params && Array.isArray(node.params)) {
|
|
273
|
-
node.params.forEach((param) => {
|
|
274
|
-
if (param.typeAnnotation &&
|
|
275
|
-
isStringLiteralUnion(param.typeAnnotation.typeAnnotation) &&
|
|
276
|
-
meetsThreshold(param.typeAnnotation.typeAnnotation)) {
|
|
277
|
-
reportViolation(param, node, param.typeAnnotation.typeAnnotation);
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
catch (error) {
|
|
283
|
-
console.error('[prefer-enum-over-string-union] Error in TSMethodSignature visitor:', error);
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
};
|
|
287
|
-
},
|
|
288
|
-
};
|
|
289
|
-
exports.default = rule;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const rule = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: 'suggestion',
|
|
6
|
+
docs: {
|
|
7
|
+
description: 'Suggest using enums instead of union types of string literals',
|
|
8
|
+
recommended: true,
|
|
9
|
+
},
|
|
10
|
+
schema: [
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
minValues: {
|
|
15
|
+
type: 'number',
|
|
16
|
+
minimum: 2,
|
|
17
|
+
default: 3,
|
|
18
|
+
},
|
|
19
|
+
allowTypeAliases: {
|
|
20
|
+
type: 'boolean',
|
|
21
|
+
default: false,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
messages: {
|
|
28
|
+
preferEnum: 'Consider using an enum instead of a union type of {{count}} string literals.',
|
|
29
|
+
},
|
|
30
|
+
fixable: 'code',
|
|
31
|
+
},
|
|
32
|
+
create(context) {
|
|
33
|
+
const options = context.options[0] || {};
|
|
34
|
+
const minValues = options.minValues || 3;
|
|
35
|
+
const allowTypeAliases = options.allowTypeAliases || false;
|
|
36
|
+
/**
|
|
37
|
+
* Check if a union type is composed solely of string literals
|
|
38
|
+
*/
|
|
39
|
+
function isStringLiteralUnion(node) {
|
|
40
|
+
if (node.type !== 'TSUnionType') {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (!node.types || !Array.isArray(node.types)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return node.types.every((type) => type.type === 'TSLiteralType' &&
|
|
47
|
+
typeof type.literal?.value === 'string');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if a property is an Angular component input
|
|
51
|
+
*/
|
|
52
|
+
function isAngularInput(node) {
|
|
53
|
+
try {
|
|
54
|
+
// Check for @Input() decorator (old style)
|
|
55
|
+
if (node.decorators && Array.isArray(node.decorators)) {
|
|
56
|
+
const hasInputDecorator = node.decorators.some((decorator) => {
|
|
57
|
+
const expression = decorator.expression;
|
|
58
|
+
return expression?.type === 'CallExpression' &&
|
|
59
|
+
expression.callee?.name === 'Input';
|
|
60
|
+
});
|
|
61
|
+
if (hasInputDecorator) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Check for input() or input.required() signal (new style)
|
|
66
|
+
if (node.value?.type === 'CallExpression') {
|
|
67
|
+
const callee = node.value.callee;
|
|
68
|
+
// Direct call: input()
|
|
69
|
+
if (callee?.name === 'input') {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
// Member call: input.required()
|
|
73
|
+
if (callee?.object?.name === 'input' && callee?.property?.name === 'required') {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error('[prefer-enum-over-string-union] Error checking Angular input:', error);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Check if a union type meets the minimum threshold
|
|
86
|
+
*/
|
|
87
|
+
function meetsThreshold(node) {
|
|
88
|
+
if (node.type !== 'TSUnionType' || !node.types) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const stringLiteralCount = node.types.filter((type) => type.type === 'TSLiteralType' &&
|
|
92
|
+
typeof type.literal?.value === 'string').length;
|
|
93
|
+
return stringLiteralCount >= minValues;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Generate enum name suggestion based on context
|
|
97
|
+
*/
|
|
98
|
+
function generateEnumName(node, parent) {
|
|
99
|
+
try {
|
|
100
|
+
// For type aliases, use the type name
|
|
101
|
+
if (parent?.type === 'TSTypeAliasDeclaration' && parent.id?.name) {
|
|
102
|
+
return parent.id.name;
|
|
103
|
+
}
|
|
104
|
+
// For properties, use property name + "Enum"
|
|
105
|
+
if (node.type === 'TSPropertySignature' && node.key?.name) {
|
|
106
|
+
return `${node.key.name.charAt(0).toUpperCase() + node.key.name.slice(1)}Enum`;
|
|
107
|
+
}
|
|
108
|
+
// For class properties, use property name + "Enum"
|
|
109
|
+
if (parent?.type === 'PropertyDefinition' && parent.key?.name) {
|
|
110
|
+
return `${parent.key.name.charAt(0).toUpperCase() + parent.key.name.slice(1)}Enum`;
|
|
111
|
+
}
|
|
112
|
+
// Default fallback
|
|
113
|
+
return 'StatusEnum';
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error('[prefer-enum-over-string-union] Error generating enum name:', error);
|
|
117
|
+
return 'StatusEnum';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Generate enum values from string literals
|
|
122
|
+
*/
|
|
123
|
+
function generateEnumValues(node) {
|
|
124
|
+
if (node.type !== 'TSUnionType' || !node.types) {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
return node.types
|
|
128
|
+
.filter((type) => type.type === 'TSLiteralType' &&
|
|
129
|
+
typeof type.literal?.value === 'string')
|
|
130
|
+
.map((type) => {
|
|
131
|
+
const value = type.literal.value;
|
|
132
|
+
// Convert to PascalCase for enum key
|
|
133
|
+
return value
|
|
134
|
+
.split(/[-_\s]+/)
|
|
135
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
136
|
+
.join('');
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Report violation with enum suggestion
|
|
141
|
+
*/
|
|
142
|
+
function reportViolation(node, parent, unionNode) {
|
|
143
|
+
const stringLiteralCount = unionNode.types.filter((type) => type.type === 'TSLiteralType' &&
|
|
144
|
+
typeof type.literal?.value === 'string').length;
|
|
145
|
+
const enumName = generateEnumName(node, parent);
|
|
146
|
+
const enumValues = generateEnumValues(unionNode);
|
|
147
|
+
context.report({
|
|
148
|
+
node: unionNode,
|
|
149
|
+
messageId: 'preferEnum',
|
|
150
|
+
data: {
|
|
151
|
+
count: stringLiteralCount.toString(),
|
|
152
|
+
},
|
|
153
|
+
fix(fixer) {
|
|
154
|
+
try {
|
|
155
|
+
const enumDeclaration = `enum ${enumName} {\n ${enumValues.map((key, index) => {
|
|
156
|
+
const value = unionNode.types[index].literal.value;
|
|
157
|
+
return `${key} = '${value}'`;
|
|
158
|
+
}).join(',\n ')}\n}`;
|
|
159
|
+
// For type aliases, replace the entire declaration
|
|
160
|
+
if (parent?.type === 'TSTypeAliasDeclaration') {
|
|
161
|
+
const typeText = context.sourceCode.getText(parent);
|
|
162
|
+
const newText = typeText.replace(/=.*/, `= ${enumName};`);
|
|
163
|
+
return fixer.replaceText(parent, newText);
|
|
164
|
+
}
|
|
165
|
+
// For other cases, suggest enum creation (no auto-fix for now)
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
catch (fixError) {
|
|
169
|
+
console.error('[prefer-enum-over-string-union] Error in fix function:', fixError);
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
// Type aliases
|
|
177
|
+
TSTypeAliasDeclaration(node) {
|
|
178
|
+
try {
|
|
179
|
+
if (allowTypeAliases) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (isStringLiteralUnion(node.typeAnnotation) && meetsThreshold(node.typeAnnotation)) {
|
|
183
|
+
reportViolation(node.typeAnnotation, node, node.typeAnnotation);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
console.error('[prefer-enum-over-string-union] Error in TSTypeAliasDeclaration visitor:', error);
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
// Interface/type properties
|
|
191
|
+
TSPropertySignature(node) {
|
|
192
|
+
try {
|
|
193
|
+
if (isAngularInput(node)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (node.typeAnnotation &&
|
|
197
|
+
isStringLiteralUnion(node.typeAnnotation.typeAnnotation) &&
|
|
198
|
+
meetsThreshold(node.typeAnnotation.typeAnnotation)) {
|
|
199
|
+
reportViolation(node, node.parent, node.typeAnnotation.typeAnnotation);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
console.error('[prefer-enum-over-string-union] Error in TSPropertySignature visitor:', error);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
// Class properties
|
|
207
|
+
PropertyDefinition(node) {
|
|
208
|
+
try {
|
|
209
|
+
if (isAngularInput(node)) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (node.typeAnnotation &&
|
|
213
|
+
isStringLiteralUnion(node.typeAnnotation.typeAnnotation) &&
|
|
214
|
+
meetsThreshold(node.typeAnnotation.typeAnnotation)) {
|
|
215
|
+
reportViolation(node, node.parent, node.typeAnnotation.typeAnnotation);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
console.error('[prefer-enum-over-string-union] Error in PropertyDefinition visitor:', error);
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
// Function parameters
|
|
223
|
+
FunctionDeclaration(node) {
|
|
224
|
+
try {
|
|
225
|
+
if (node.params && Array.isArray(node.params)) {
|
|
226
|
+
node.params.forEach((param) => {
|
|
227
|
+
if (param.typeAnnotation &&
|
|
228
|
+
isStringLiteralUnion(param.typeAnnotation.typeAnnotation) &&
|
|
229
|
+
meetsThreshold(param.typeAnnotation.typeAnnotation)) {
|
|
230
|
+
reportViolation(param, node, param.typeAnnotation.typeAnnotation);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
console.error('[prefer-enum-over-string-union] Error in FunctionDeclaration visitor:', error);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
// Arrow function parameters
|
|
240
|
+
ArrowFunctionExpression(node) {
|
|
241
|
+
try {
|
|
242
|
+
if (node.params && Array.isArray(node.params)) {
|
|
243
|
+
node.params.forEach((param) => {
|
|
244
|
+
if (param.typeAnnotation &&
|
|
245
|
+
isStringLiteralUnion(param.typeAnnotation.typeAnnotation) &&
|
|
246
|
+
meetsThreshold(param.typeAnnotation.typeAnnotation)) {
|
|
247
|
+
reportViolation(param, node, param.typeAnnotation.typeAnnotation);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
console.error('[prefer-enum-over-string-union] Error in ArrowFunctionExpression visitor:', error);
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
// Variable declarations
|
|
257
|
+
VariableDeclarator(node) {
|
|
258
|
+
try {
|
|
259
|
+
if (node.typeAnnotation &&
|
|
260
|
+
isStringLiteralUnion(node.typeAnnotation.typeAnnotation) &&
|
|
261
|
+
meetsThreshold(node.typeAnnotation.typeAnnotation)) {
|
|
262
|
+
reportViolation(node, node.parent, node.typeAnnotation.typeAnnotation);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
console.error('[prefer-enum-over-string-union] Error in VariableDeclarator visitor:', error);
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
// Method signatures
|
|
270
|
+
TSMethodSignature(node) {
|
|
271
|
+
try {
|
|
272
|
+
if (node.params && Array.isArray(node.params)) {
|
|
273
|
+
node.params.forEach((param) => {
|
|
274
|
+
if (param.typeAnnotation &&
|
|
275
|
+
isStringLiteralUnion(param.typeAnnotation.typeAnnotation) &&
|
|
276
|
+
meetsThreshold(param.typeAnnotation.typeAnnotation)) {
|
|
277
|
+
reportViolation(param, node, param.typeAnnotation.typeAnnotation);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
console.error('[prefer-enum-over-string-union] Error in TSMethodSignature visitor:', error);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
exports.default = rule;
|
|
290
290
|
//# sourceMappingURL=prefer-enum-over-string-union.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-enum-over-string-union.js","sourceRoot":"","sources":["../../../src/plugin/rules/prefer-enum-over-string-union.ts"],"names":[],"mappings":";;AAOA,MAAM,IAAI,GAAoB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,+DAA+D;YAC5E,WAAW,EAAE,IAAI;SAClB;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,SAAS,EAAE;wBACT,IAAI,EAAE,QAAQ;wBACd,OAAO,EAAE,CAAC;wBACV,OAAO,EAAE,CAAC;qBACX;oBACD,gBAAgB,EAAE;wBAChB,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,KAAK;qBACf;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,QAAQ,EAAE;YACR,UAAU,EAAE,8EAA8E;SAC3F;QACD,OAAO,EAAE,MAAM;KAChB;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,OAAO,GAAgB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACtD,MAAM,SAAS,GAAW,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC;QACjD,MAAM,gBAAgB,GAAY,OAAO,CAAC,gBAAgB,IAAI,KAAK,CAAC;QAEpE;;WAEG;QACH,SAAS,oBAAoB,CAAC,IAAS;YACrC,IAAI,IAAI,CAAC,IAAI,KA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AO,CAAC,CAAC;wBAC5C,CAAC;wBAED,+DAA+D;wBAC/D,OAAO,IAAI,CAAC;oBACd,CAAC;oBAAC,OAAO,QAAQ,EAAE,CAAC;wBAClB,OAAO,CAAC,KAAK,CAAC,wDAAwD,EAAE,QAAQ,CAAC,CAAC;wBAElF,OAAO,IAAI,CAAC;oBACd,CAAC;gBACH,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO;YACL,eAAe;YACf,sBAAsB,CAAC,IAAS
|
|
1
|
+
{"version":3,"file":"prefer-enum-over-string-union.js","sourceRoot":"","sources":["../../../src/plugin/rules/prefer-enum-over-string-union.ts"],"names":[],"mappings":";;AAOA,MAAM,IAAI,GAAoB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,+DAA+D;YAC5E,WAAW,EAAE,IAAI;SAClB;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,SAAS,EAAE;wBACT,IAAI,EAAE,QAAQ;wBACd,OAAO,EAAE,CAAC;wBACV,OAAO,EAAE,CAAC;qBACX;oBACD,gBAAgB,EAAE;wBAChB,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,KAAK;qBACf;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,QAAQ,EAAE;YACR,UAAU,EAAE,8EAA8E;SAC3F;QACD,OAAO,EAAE,MAAM;KAChB;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,OAAO,GAAgB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACtD,MAAM,SAAS,GAAW,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC;QACjD,MAAM,gBAAgB,GAAY,OAAO,CAAC,gBAAgB,IAAI,KAAK,CAAC;QAEpE;;WAEG;QACH,SAAS,oBAAoB,CAAC,IAAS;YACrC,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa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AAM,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE;4BACjC,IAAI,KAAK,CAAC,cAAc;gCACpB,oBAAoB,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;gCACzD,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,CAAC;gCACxD,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;4BACpE,CAAC;wBACH,CAAC,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,qEAAqE,EAAE,KAAK,CAAC,CAAC;gBAC9F,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,kBAAe,IAAI,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Rule } from 'eslint';
|
|
2
|
-
declare const rule: Rule.RuleModule;
|
|
3
|
-
export default rule;
|
|
1
|
+
import { Rule } from 'eslint';
|
|
2
|
+
declare const rule: Rule.RuleModule;
|
|
3
|
+
export default rule;
|
|
4
4
|
//# sourceMappingURL=prefer-interface-over-duplicate-types.d.ts.map
|