@futdevpro/dynamo-eslint 1.14.3 → 1.14.4
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/.eslintrc.json +4 -0
- package/.vscode/settings.json +13 -0
- package/README.md +17 -2
- package/build/configs/base.js +2 -1
- package/build/configs/base.js.map +1 -1
- package/build/plugin/index.d.ts +2 -0
- package/build/plugin/index.d.ts.map +1 -1
- package/build/plugin/index.js +3 -0
- package/build/plugin/index.js.map +1 -1
- package/build/plugin/rules/explicit-types.d.ts +4 -0
- package/build/plugin/rules/explicit-types.d.ts.map +1 -0
- package/build/plugin/rules/explicit-types.js +165 -0
- package/build/plugin/rules/explicit-types.js.map +1 -0
- package/build/plugin/rules/explicit-types.spec.d.ts +2 -0
- package/build/plugin/rules/explicit-types.spec.d.ts.map +1 -0
- package/build/plugin/rules/explicit-types.spec.js +162 -0
- package/build/plugin/rules/explicit-types.spec.js.map +1 -0
- package/build/plugin/rules/import/no-import-type.d.ts.map +1 -1
- package/build/plugin/rules/import/no-import-type.js +23 -12
- package/build/plugin/rules/import/no-import-type.js.map +1 -1
- package/build/plugin/rules/import/no-js-import.d.ts.map +1 -1
- package/build/plugin/rules/import/no-js-import.js +22 -11
- package/build/plugin/rules/import/no-js-import.js.map +1 -1
- package/build/plugin/rules/naming-patterns.d.ts.map +1 -1
- package/build/plugin/rules/naming-patterns.js +7 -2
- package/build/plugin/rules/naming-patterns.js.map +1 -1
- package/build/scripts/dynamo-fix.d.ts +24 -0
- package/build/scripts/dynamo-fix.d.ts.map +1 -1
- package/build/scripts/dynamo-fix.js +57 -2
- package/build/scripts/dynamo-fix.js.map +1 -1
- package/build/scripts/eslintrc-audit.d.ts +24 -0
- package/build/scripts/eslintrc-audit.d.ts.map +1 -1
- package/build/scripts/eslintrc-audit.js +65 -0
- package/build/scripts/eslintrc-audit.js.map +1 -1
- package/build/scripts/fix-return-types.d.ts +25 -0
- package/build/scripts/fix-return-types.d.ts.map +1 -1
- package/build/scripts/fix-return-types.js +80 -9
- package/build/scripts/fix-return-types.js.map +1 -1
- package/build/scripts/validate-imports.d.ts +24 -0
- package/build/scripts/validate-imports.d.ts.map +1 -1
- package/build/scripts/validate-imports.js +62 -1
- package/build/scripts/validate-imports.js.map +1 -1
- package/build/scripts/validate-naming.d.ts +24 -0
- package/build/scripts/validate-naming.d.ts.map +1 -1
- package/build/scripts/validate-naming.js +72 -9
- package/build/scripts/validate-naming.js.map +1 -1
- package/eslint.config.js +9 -49
- package/futdevpro-dynamo-eslint-01.14.4.tgz +0 -0
- package/package.json +1 -1
- package/src/configs/base.ts +2 -1
- package/src/plugin/index.ts +3 -0
- package/src/plugin/rules/explicit-types.spec.ts +190 -0
- package/src/plugin/rules/explicit-types.ts +169 -0
- package/src/plugin/rules/import/no-import-type.ts +21 -12
- package/src/plugin/rules/import/no-js-import.ts +21 -13
- package/src/plugin/rules/naming-patterns.ts +6 -2
- package/src/scripts/dynamo-fix.ts +66 -2
- package/src/scripts/eslintrc-audit.ts +73 -2
- package/src/scripts/fix-return-types.ts +91 -9
- package/src/scripts/validate-imports.ts +71 -2
- package/src/scripts/validate-naming.ts +108 -17
- package/futdevpro-dynamo-eslint-01.14.3.tgz +0 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"eslint.run": "onSave",
|
|
3
|
+
"eslint.workingDirectories": [{ "mode": "auto" }],
|
|
4
|
+
"eslint.enable": true,
|
|
5
|
+
"eslint.debug": true,
|
|
6
|
+
"editor.codeActionsOnSave": {
|
|
7
|
+
"source.fixAll.eslint": "explicit"
|
|
8
|
+
},
|
|
9
|
+
"eslint.validate": [
|
|
10
|
+
"javascript",
|
|
11
|
+
"typescript"
|
|
12
|
+
]
|
|
13
|
+
}
|
package/README.md
CHANGED
|
@@ -169,6 +169,9 @@ This package includes custom ESLint rules for Dynamo conventions:
|
|
|
169
169
|
### Naming Rules
|
|
170
170
|
- **`@futdevpro/dynamo/naming-patterns`**: Enforces DyFM naming conventions
|
|
171
171
|
|
|
172
|
+
### Type Rules
|
|
173
|
+
- **`@futdevpro/dynamo/explicit-types`**: Enforces explicit type annotations on all TypeScript declarations (functions, variables, parameters, class properties, destructuring)
|
|
174
|
+
|
|
172
175
|
## 🛠️ CLI Validation Tools
|
|
173
176
|
|
|
174
177
|
Use these commands to validate your codebase:
|
|
@@ -186,7 +189,7 @@ dynamo-eslintrc-audit
|
|
|
186
189
|
# Run comprehensive fixes
|
|
187
190
|
dynamo-fix
|
|
188
191
|
|
|
189
|
-
# Fix missing
|
|
192
|
+
# Fix missing type annotations (functions, variables, parameters, class properties)
|
|
190
193
|
dynamo-fix-return-types
|
|
191
194
|
```
|
|
192
195
|
|
|
@@ -203,7 +206,7 @@ Add to your `package.json`:
|
|
|
203
206
|
"validate:naming": "dynamo-validate-naming",
|
|
204
207
|
"audit:eslintrc": "dynamo-eslintrc-audit",
|
|
205
208
|
"fix": "dynamo-fix",
|
|
206
|
-
"fix:
|
|
209
|
+
"fix:types": "dynamo-fix-return-types"
|
|
207
210
|
}
|
|
208
211
|
}
|
|
209
212
|
```
|
|
@@ -287,6 +290,18 @@ return ts.visitEachChild(node, visit, {} as ts.TransformationContext);
|
|
|
287
290
|
|
|
288
291
|
This ensures compatibility with TypeScript's AST transformation APIs.
|
|
289
292
|
|
|
293
|
+
### Enhanced Type Annotation Fixing
|
|
294
|
+
|
|
295
|
+
The `dynamo-fix-return-types` script now handles comprehensive type annotation fixing:
|
|
296
|
+
|
|
297
|
+
- **Function declarations**: Adds return type annotations
|
|
298
|
+
- **Arrow functions**: Adds return type annotations
|
|
299
|
+
- **Variable declarations**: Adds type annotations based on initializer types
|
|
300
|
+
- **Function parameters**: Adds parameter type annotations
|
|
301
|
+
- **Class properties**: Adds property type annotations
|
|
302
|
+
|
|
303
|
+
The script uses TypeScript's type checker to infer appropriate types and automatically adds them to your code.
|
|
304
|
+
|
|
290
305
|
## 📚 Self-Linting
|
|
291
306
|
|
|
292
307
|
This package uses its own presets and rules for self-linting. The ESLint v9 flat config is in `eslint.config.js` and demonstrates advanced configuration patterns.
|
package/build/configs/base.js
CHANGED
|
@@ -49,7 +49,7 @@ module.exports = [
|
|
|
49
49
|
// ESLint recommended rules
|
|
50
50
|
'no-warning-comments': ['warn', { terms: ['todo', 'fixme', 'removable', '??'], location: 'anywhere' }],
|
|
51
51
|
'indent': ['warn', 2, { SwitchCase: 1 }],
|
|
52
|
-
'max-len': ['warn', { code:
|
|
52
|
+
'max-len': ['warn', { code: 120, comments: 120 }],
|
|
53
53
|
'max-lines': ['warn', 1000],
|
|
54
54
|
'linebreak-style': 'off',
|
|
55
55
|
'semi': ['warn', 'always'],
|
|
@@ -81,6 +81,7 @@ module.exports = [
|
|
|
81
81
|
'@typescript-eslint/no-explicit-any': 'warn',
|
|
82
82
|
'@typescript-eslint/typedef': 'warn',
|
|
83
83
|
// Dynamo custom rules
|
|
84
|
+
'@futdevpro/dynamo/explicit-types': 'warn',
|
|
84
85
|
'@futdevpro/dynamo/import-order': 'warn',
|
|
85
86
|
'@futdevpro/dynamo/naming-patterns': 'warn',
|
|
86
87
|
'@futdevpro/dynamo/no-import-type': 'warn',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/configs/base.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,MAAM,QAAQ,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;AAC7D,MAAM,mBAAmB,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AACpE,MAAM,4BAA4B,GAAG,OAAO,CAAC,yCAAyC,CAAC,CAAC;AACxF,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAE1C,MAAM,CAAC,OAAO,GAAG;IACf;QACE,OAAO,EAAE;YACP,iBAAiB;YACjB,SAAS;YACT,UAAU;YACV,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1,6 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
rules: {
|
|
3
|
+
'explicit-types': import("eslint").Rule.RuleModule;
|
|
3
4
|
'import-order': import("eslint").Rule.RuleModule;
|
|
4
5
|
'no-import-type': import("eslint").Rule.RuleModule;
|
|
5
6
|
'no-js-import': import("eslint").Rule.RuleModule;
|
|
@@ -8,6 +9,7 @@ declare const _default: {
|
|
|
8
9
|
configs: {
|
|
9
10
|
recommended: {
|
|
10
11
|
rules: {
|
|
12
|
+
'@futdevpro/dynamo/explicit-types': string;
|
|
11
13
|
'@futdevpro/dynamo/import-order': string;
|
|
12
14
|
'@futdevpro/dynamo/no-import-type': string;
|
|
13
15
|
'@futdevpro/dynamo/no-js-import': string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAMA,kBAqBE"}
|
package/build/plugin/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const tslib_1 = require("tslib");
|
|
3
|
+
const explicit_types_1 = tslib_1.__importDefault(require("./rules/explicit-types"));
|
|
3
4
|
const import_order_1 = tslib_1.__importDefault(require("./rules/import/import-order"));
|
|
4
5
|
const naming_patterns_1 = tslib_1.__importDefault(require("./rules/naming-patterns"));
|
|
5
6
|
const no_import_type_1 = tslib_1.__importDefault(require("./rules/import/no-import-type"));
|
|
6
7
|
const no_js_import_1 = tslib_1.__importDefault(require("./rules/import/no-js-import"));
|
|
7
8
|
module.exports = {
|
|
8
9
|
rules: {
|
|
10
|
+
'explicit-types': explicit_types_1.default,
|
|
9
11
|
'import-order': import_order_1.default,
|
|
10
12
|
'no-import-type': no_import_type_1.default,
|
|
11
13
|
'no-js-import': no_js_import_1.default,
|
|
@@ -14,6 +16,7 @@ module.exports = {
|
|
|
14
16
|
configs: {
|
|
15
17
|
recommended: {
|
|
16
18
|
rules: {
|
|
19
|
+
'@futdevpro/dynamo/explicit-types': 'warn',
|
|
17
20
|
'@futdevpro/dynamo/import-order': 'warn',
|
|
18
21
|
'@futdevpro/dynamo/no-import-type': 'warn',
|
|
19
22
|
'@futdevpro/dynamo/no-js-import': 'warn',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":";;AAAA,uFAA0D;AAC1D,sFAAyD;AACzD,2FAA6D;AAC7D,uFAA4D;AAE5D,iBAAS;IACP,KAAK,EAAE;QACL,cAAc,EAAE,sBAAe;QAC/B,gBAAgB,EAAE,wBAAgB;QAClC,cAAc,EAAE,sBAAiB;QAEjC,iBAAiB,EAAE,yBAAkB;KACtC;IACD,OAAO,EAAE;QACP,WAAW,EAAE;YACX,KAAK,EAAE;gBACL,gCAAgC,EAAE,MAAM;gBACxC,kCAAkC,EAAE,MAAM;gBAC1C,gCAAgC,EAAE,MAAM;gBAExC,mCAAmC,EAAE,MAAM;aAC5C;SACF;KACF;CACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":";;AAAA,oFAAuD;AACvD,uFAA0D;AAC1D,sFAAyD;AACzD,2FAA6D;AAC7D,uFAA4D;AAE5D,iBAAS;IACP,KAAK,EAAE;QACL,gBAAgB,EAAE,wBAAiB;QACnC,cAAc,EAAE,sBAAe;QAC/B,gBAAgB,EAAE,wBAAgB;QAClC,cAAc,EAAE,sBAAiB;QAEjC,iBAAiB,EAAE,yBAAkB;KACtC;IACD,OAAO,EAAE;QACP,WAAW,EAAE;YACX,KAAK,EAAE;gBACL,kCAAkC,EAAE,MAAM;gBAC1C,gCAAgC,EAAE,MAAM;gBACxC,kCAAkC,EAAE,MAAM;gBAC1C,gCAAgC,EAAE,MAAM;gBAExC,mCAAmC,EAAE,MAAM;aAC5C;SACF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explicit-types.d.ts","sourceRoot":"","sources":["../../../src/plugin/rules/explicit-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAoKhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const rule = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: 'suggestion',
|
|
6
|
+
docs: {
|
|
7
|
+
description: 'Enforce explicit type annotations on all TypeScript declarations',
|
|
8
|
+
recommended: true,
|
|
9
|
+
},
|
|
10
|
+
schema: [],
|
|
11
|
+
messages: {
|
|
12
|
+
missingReturnType: 'Function "{{name}}" must have an explicit return type annotation.',
|
|
13
|
+
missingArrowReturnType: 'Arrow function must have an explicit return type annotation.',
|
|
14
|
+
missingVariableType: 'Variable "{{name}}" must have an explicit type annotation.',
|
|
15
|
+
missingParameterType: 'Parameter "{{name}}" must have an explicit type annotation.',
|
|
16
|
+
missingPropertyType: 'Class property "{{name}}" must have an explicit type annotation.',
|
|
17
|
+
missingDestructuringType: 'Destructuring assignment must have explicit type annotations.',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
create(context) {
|
|
21
|
+
return {
|
|
22
|
+
// Function declarations
|
|
23
|
+
FunctionDeclaration(node) {
|
|
24
|
+
try {
|
|
25
|
+
// Check return type
|
|
26
|
+
if (!node.returnType) {
|
|
27
|
+
context.report({
|
|
28
|
+
node,
|
|
29
|
+
messageId: 'missingReturnType',
|
|
30
|
+
data: { name: node.id?.name || 'anonymous' },
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// Check function parameters with defensive checks
|
|
34
|
+
if (node.params && Array.isArray(node.params)) {
|
|
35
|
+
node.params.forEach((param) => {
|
|
36
|
+
try {
|
|
37
|
+
if (param && param.type === 'Identifier' && !param.typeAnnotation) {
|
|
38
|
+
context.report({
|
|
39
|
+
node: param,
|
|
40
|
+
messageId: 'missingParameterType',
|
|
41
|
+
data: { name: param.name || 'unknown' },
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (paramError) {
|
|
46
|
+
console.error('[explicit-types] Error processing function parameter:', paramError);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error('[explicit-types] Error in FunctionDeclaration visitor:', error);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
// Arrow functions
|
|
56
|
+
ArrowFunctionExpression(node) {
|
|
57
|
+
try {
|
|
58
|
+
// Check return type
|
|
59
|
+
if (!node.returnType) {
|
|
60
|
+
context.report({
|
|
61
|
+
node,
|
|
62
|
+
messageId: 'missingArrowReturnType',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Check arrow function parameters with defensive checks
|
|
66
|
+
if (node.params && Array.isArray(node.params)) {
|
|
67
|
+
node.params.forEach((param) => {
|
|
68
|
+
try {
|
|
69
|
+
if (param && param.type === 'Identifier' && !param.typeAnnotation) {
|
|
70
|
+
context.report({
|
|
71
|
+
node: param,
|
|
72
|
+
messageId: 'missingParameterType',
|
|
73
|
+
data: { name: param.name || 'unknown' },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (paramError) {
|
|
78
|
+
console.error('[explicit-types] Error processing arrow function parameter:', paramError);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error('[explicit-types] Error in ArrowFunctionExpression visitor:', error);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
// Variable declarations
|
|
88
|
+
VariableDeclarator(node) {
|
|
89
|
+
try {
|
|
90
|
+
// Defensive check for node.id
|
|
91
|
+
if (!node.id) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!node.id.typeAnnotation) {
|
|
95
|
+
// Skip if variable is initialized with a typed value that can be inferred
|
|
96
|
+
const hasTypedInitializer = node.init && (node.init.type === 'CallExpression' ||
|
|
97
|
+
node.init.type === 'NewExpression' ||
|
|
98
|
+
node.init.type === 'ArrayExpression' ||
|
|
99
|
+
node.init.type === 'ObjectExpression' ||
|
|
100
|
+
node.init.type === 'Literal');
|
|
101
|
+
if (!hasTypedInitializer) {
|
|
102
|
+
context.report({
|
|
103
|
+
node: node.id,
|
|
104
|
+
messageId: 'missingVariableType',
|
|
105
|
+
data: { name: node.id?.name || 'destructured' },
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error('[explicit-types] Error in VariableDeclarator visitor:', error);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
// Class properties
|
|
115
|
+
PropertyDefinition(node) {
|
|
116
|
+
try {
|
|
117
|
+
// Defensive check for node.key
|
|
118
|
+
if (!node.key) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!node.typeAnnotation && !node.value) {
|
|
122
|
+
context.report({
|
|
123
|
+
node: node.key,
|
|
124
|
+
messageId: 'missingPropertyType',
|
|
125
|
+
data: { name: node.key?.name || 'computed' },
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
console.error('[explicit-types] Error in PropertyDefinition visitor:', error);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
// Object destructuring
|
|
134
|
+
ObjectPattern(node) {
|
|
135
|
+
try {
|
|
136
|
+
if (!node.typeAnnotation) {
|
|
137
|
+
context.report({
|
|
138
|
+
node,
|
|
139
|
+
messageId: 'missingDestructuringType',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.error('[explicit-types] Error in ObjectPattern visitor:', error);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
// Array destructuring
|
|
148
|
+
ArrayPattern(node) {
|
|
149
|
+
try {
|
|
150
|
+
if (!node.typeAnnotation) {
|
|
151
|
+
context.report({
|
|
152
|
+
node,
|
|
153
|
+
messageId: 'missingDestructuringType',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
console.error('[explicit-types] Error in ArrayPattern visitor:', error);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
exports.default = rule;
|
|
165
|
+
//# sourceMappingURL=explicit-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explicit-types.js","sourceRoot":"","sources":["../../../src/plugin/rules/explicit-types.ts"],"names":[],"mappings":";;AAEA,MAAM,IAAI,GAAoB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,kEAAkE;YAC/E,WAAW,EAAE,IAAI;SAClB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,iBAAiB,EAAE,mEAAmE;YACtF,sBAAsB,EAAE,8DAA8D;YACtF,mBAAmB,EAAE,4DAA4D;YACjF,oBAAoB,EAAE,6DAA6D;YACnF,mBAAmB,EAAE,kEAAkE;YACvF,wBAAwB,EAAE,+DAA+D;SAC1F;KACF;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,wBAAwB;YACxB,mBAAmB,CAAC,IAAS;gBAC3B,IAAI,CAAC;oBACH,oBAAoB;oBACpB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;wBACrB,OAAO,CAAC,MAAM,CA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AAC,KAAK,CAAC,kDAAkD,EAAE,KAAK,CAAC,CAAC;gBAC3E,CAAC;YACH,CAAC;YAED,sBAAsB;YACtB,YAAY,CAAC,IAAS;gBACpB,IAAI,CAAC;oBACH,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;wBACzB,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,SAAS,EAAE,0BAA0B;yBACtC,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,iDAAiD,EAAE,KAAK,CAAC,CAAC;gBAC1E,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,kBAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explicit-types.spec.d.ts","sourceRoot":"","sources":["../../../src/plugin/rules/explicit-types.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const explicit_types_1 = tslib_1.__importDefault(require("./explicit-types"));
|
|
5
|
+
describe('| explicit-types', () => {
|
|
6
|
+
it('| should be a valid ESLint rule', () => {
|
|
7
|
+
expect(explicit_types_1.default.meta?.type).toBe('suggestion');
|
|
8
|
+
expect(explicit_types_1.default.meta?.docs?.description).toContain('explicit type annotations');
|
|
9
|
+
});
|
|
10
|
+
it('| should have create function that returns visitor object', () => {
|
|
11
|
+
const mockContext = {
|
|
12
|
+
report: () => { },
|
|
13
|
+
};
|
|
14
|
+
const result = explicit_types_1.default.create(mockContext);
|
|
15
|
+
expect(typeof result).toBe('object');
|
|
16
|
+
expect(typeof result.FunctionDeclaration).toBe('function');
|
|
17
|
+
expect(typeof result.ArrowFunctionExpression).toBe('function');
|
|
18
|
+
expect(typeof result.VariableDeclarator).toBe('function');
|
|
19
|
+
expect(typeof result.PropertyDefinition).toBe('function');
|
|
20
|
+
});
|
|
21
|
+
it('| should report missing return types on function declarations', () => {
|
|
22
|
+
const mockContext = {
|
|
23
|
+
report: (options) => {
|
|
24
|
+
expect(options.messageId).toBe('missingReturnType');
|
|
25
|
+
expect(options.data.name).toBe('testFunction');
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const mockNode = {
|
|
29
|
+
type: 'FunctionDeclaration',
|
|
30
|
+
id: { name: 'testFunction' },
|
|
31
|
+
returnType: null,
|
|
32
|
+
params: [],
|
|
33
|
+
};
|
|
34
|
+
const rule = explicit_types_1.default.create(mockContext);
|
|
35
|
+
rule.FunctionDeclaration(mockNode);
|
|
36
|
+
});
|
|
37
|
+
it('| should not report when function has return type', () => {
|
|
38
|
+
const mockContext = {
|
|
39
|
+
report: (options) => {
|
|
40
|
+
fail('Should not report when function has return type');
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const mockNode = {
|
|
44
|
+
type: 'FunctionDeclaration',
|
|
45
|
+
id: { name: 'testFunction' },
|
|
46
|
+
returnType: { type: 'TSTypeAnnotation' },
|
|
47
|
+
params: [],
|
|
48
|
+
};
|
|
49
|
+
const rule = explicit_types_1.default.create(mockContext);
|
|
50
|
+
rule.FunctionDeclaration(mockNode);
|
|
51
|
+
});
|
|
52
|
+
it('| should report missing return types on arrow functions', () => {
|
|
53
|
+
const mockContext = {
|
|
54
|
+
report: (options) => {
|
|
55
|
+
expect(options.messageId).toBe('missingArrowReturnType');
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
const mockNode = {
|
|
59
|
+
type: 'ArrowFunctionExpression',
|
|
60
|
+
returnType: null,
|
|
61
|
+
params: [],
|
|
62
|
+
};
|
|
63
|
+
const rule = explicit_types_1.default.create(mockContext);
|
|
64
|
+
rule.ArrowFunctionExpression(mockNode);
|
|
65
|
+
});
|
|
66
|
+
it('| should report missing types on variable declarations', () => {
|
|
67
|
+
const mockContext = {
|
|
68
|
+
report: (options) => {
|
|
69
|
+
expect(options.messageId).toBe('missingVariableType');
|
|
70
|
+
expect(options.data.name).toBe('testVar');
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
const mockNode = {
|
|
74
|
+
type: 'VariableDeclarator',
|
|
75
|
+
id: { name: 'testVar', typeAnnotation: null },
|
|
76
|
+
init: null,
|
|
77
|
+
};
|
|
78
|
+
const rule = explicit_types_1.default.create(mockContext);
|
|
79
|
+
rule.VariableDeclarator(mockNode);
|
|
80
|
+
});
|
|
81
|
+
it('| should not report when variable has type annotation', () => {
|
|
82
|
+
const mockContext = {
|
|
83
|
+
report: (options) => {
|
|
84
|
+
fail('Should not report when variable has type annotation');
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
const mockNode = {
|
|
88
|
+
type: 'VariableDeclarator',
|
|
89
|
+
id: { name: 'testVar', typeAnnotation: { type: 'TSTypeAnnotation' } },
|
|
90
|
+
init: null,
|
|
91
|
+
};
|
|
92
|
+
const rule = explicit_types_1.default.create(mockContext);
|
|
93
|
+
rule.VariableDeclarator(mockNode);
|
|
94
|
+
});
|
|
95
|
+
it('| should not report when variable has typed initializer', () => {
|
|
96
|
+
const mockContext = {
|
|
97
|
+
report: (options) => {
|
|
98
|
+
fail('Should not report when variable has typed initializer');
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
const mockNode = {
|
|
102
|
+
type: 'VariableDeclarator',
|
|
103
|
+
id: { name: 'testVar', typeAnnotation: null },
|
|
104
|
+
init: { type: 'CallExpression' },
|
|
105
|
+
};
|
|
106
|
+
const rule = explicit_types_1.default.create(mockContext);
|
|
107
|
+
rule.VariableDeclarator(mockNode);
|
|
108
|
+
});
|
|
109
|
+
it('| should report missing parameter types', () => {
|
|
110
|
+
const mockContext = {
|
|
111
|
+
report: (options) => {
|
|
112
|
+
expect(options.messageId).toBe('missingParameterType');
|
|
113
|
+
expect(options.data.name).toBe('param');
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
const mockNode = {
|
|
117
|
+
type: 'FunctionDeclaration',
|
|
118
|
+
id: { name: 'testFunction' },
|
|
119
|
+
returnType: { type: 'TSTypeAnnotation' },
|
|
120
|
+
params: [
|
|
121
|
+
{ type: 'Identifier', name: 'param', typeAnnotation: null }
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
const rule = explicit_types_1.default.create(mockContext);
|
|
125
|
+
rule.FunctionDeclaration(mockNode);
|
|
126
|
+
});
|
|
127
|
+
it('| should report missing class property types', () => {
|
|
128
|
+
const mockContext = {
|
|
129
|
+
report: (options) => {
|
|
130
|
+
expect(options.messageId).toBe('missingPropertyType');
|
|
131
|
+
expect(options.data.name).toBe('property');
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
const mockNode = {
|
|
135
|
+
type: 'PropertyDefinition',
|
|
136
|
+
key: { name: 'property' },
|
|
137
|
+
typeAnnotation: null,
|
|
138
|
+
value: null,
|
|
139
|
+
};
|
|
140
|
+
const rule = explicit_types_1.default.create(mockContext);
|
|
141
|
+
rule.PropertyDefinition(mockNode);
|
|
142
|
+
});
|
|
143
|
+
it('| should report missing destructuring types', () => {
|
|
144
|
+
const mockContext = {
|
|
145
|
+
report: (options) => {
|
|
146
|
+
expect(options.messageId).toBe('missingDestructuringType');
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
const objectPatternNode = {
|
|
150
|
+
type: 'ObjectPattern',
|
|
151
|
+
typeAnnotation: null,
|
|
152
|
+
};
|
|
153
|
+
const arrayPatternNode = {
|
|
154
|
+
type: 'ArrayPattern',
|
|
155
|
+
typeAnnotation: null,
|
|
156
|
+
};
|
|
157
|
+
const rule = explicit_types_1.default.create(mockContext);
|
|
158
|
+
rule.ObjectPattern(objectPatternNode);
|
|
159
|
+
rule.ArrayPattern(arrayPatternNode);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
//# sourceMappingURL=explicit-types.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|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CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-import-type.d.ts","sourceRoot":"","sources":["../../../../src/plugin/rules/import/no-import-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"no-import-type.d.ts","sourceRoot":"","sources":["../../../../src/plugin/rules/import/no-import-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAyChB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -14,18 +14,29 @@ const rule = {
|
|
|
14
14
|
const sourceCode = context.sourceCode;
|
|
15
15
|
return {
|
|
16
16
|
ImportDeclaration(node) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
try {
|
|
18
|
+
// Check for import type usage
|
|
19
|
+
if (node.importKind === 'type') {
|
|
20
|
+
context.report({
|
|
21
|
+
node,
|
|
22
|
+
messageId: 'forbiddenImportType',
|
|
23
|
+
fix(fixer) {
|
|
24
|
+
try {
|
|
25
|
+
// Remove 'type' keyword
|
|
26
|
+
const importText = sourceCode.getText(node);
|
|
27
|
+
const newImportText = importText.replace(/import\s+type\s+/, 'import ');
|
|
28
|
+
return fixer.replaceText(node, newImportText);
|
|
29
|
+
}
|
|
30
|
+
catch (fixError) {
|
|
31
|
+
console.error('[no-import-type] Error in fix function:', fixError);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error('[no-import-type] Error in ImportDeclaration visitor:', error);
|
|
29
40
|
}
|
|
30
41
|
},
|
|
31
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-import-type.js","sourceRoot":"","sources":["../../../../src/plugin/rules/import/no-import-type.ts"],"names":[],"mappings":";;AAEA,MAAM,IAAI,GAAoB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,EAAE,WAAW,EAAE,oCAAoC,EAAE;QAC3D,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,mBAAmB,EAAE,oCAAoC;SAC1D;QACD,OAAO,EAAE,MAAM;KAChB;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QAEtC,OAAO;YACL,iBAAiB,CAAC,IAAS;gBACzB,8BAA8B;
|
|
1
|
+
{"version":3,"file":"no-import-type.js","sourceRoot":"","sources":["../../../../src/plugin/rules/import/no-import-type.ts"],"names":[],"mappings":";;AAEA,MAAM,IAAI,GAAoB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,EAAE,WAAW,EAAE,oCAAoC,EAAE;QAC3D,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,mBAAmB,EAAE,oCAAoC;SAC1D;QACD,OAAO,EAAE,MAAM;KAChB;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QAEtC,OAAO;YACL,iBAAiB,CAAC,IAAS;gBACzB,IAAI,CAAC;oBACH,8BAA8B;oBAC9B,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;wBAC/B,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,SAAS,EAAE,qBAAqB;4BAChC,GAAG,CAAC,KAAK;gCACP,IAAI,CAAC;oCACH,wBAAwB;oCACxB,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;oCAC5C,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;oCAExE,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;gCAChD,CAAC;gCAAC,OAAO,QAAQ,EAAE,CAAC;oCAClB,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,QAAQ,CAAC,CAAC;oCACnE,OAAO,IAAI,CAAC;gCACd,CAAC;4BACH,CAAC;yBACF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,sDAAsD,EAAE,KAAK,CAAC,CAAC;gBAC/E,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,kBAAe,IAAI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-js-import.d.ts","sourceRoot":"","sources":["../../../../src/plugin/rules/import/no-js-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"no-js-import.d.ts","sourceRoot":"","sources":["../../../../src/plugin/rules/import/no-js-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAsChB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -13,17 +13,28 @@ const rule = {
|
|
|
13
13
|
create(context) {
|
|
14
14
|
return {
|
|
15
15
|
ImportDeclaration(node) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
try {
|
|
17
|
+
const source = node.source?.value;
|
|
18
|
+
if (source && source.endsWith('.js')) {
|
|
19
|
+
context.report({
|
|
20
|
+
node: node.source,
|
|
21
|
+
messageId: 'forbiddenJsExtension',
|
|
22
|
+
fix(fixer) {
|
|
23
|
+
try {
|
|
24
|
+
// Remove .js extension
|
|
25
|
+
const newSource = source.replace(/\.js$/, '');
|
|
26
|
+
return fixer.replaceText(node.source, `'${newSource}'`);
|
|
27
|
+
}
|
|
28
|
+
catch (fixError) {
|
|
29
|
+
console.error('[no-js-import] Error in fix function:', fixError);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error('[no-js-import] Error in ImportDeclaration visitor:', error);
|
|
27
38
|
}
|
|
28
39
|
},
|
|
29
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-js-import.js","sourceRoot":"","sources":["../../../../src/plugin/rules/import/no-js-import.ts"],"names":[],"mappings":";;AAEA,MAAM,IAAI,GAAoB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,EAAE,WAAW,EAAE,qCAAqC,EAAE;QAC5D,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,oBAAoB,EAAE,sEAAsE;SAC7F;QACD,OAAO,EAAE,MAAM;KAChB;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,iBAAiB,CAAC,IAAS;gBACzB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"no-js-import.js","sourceRoot":"","sources":["../../../../src/plugin/rules/import/no-js-import.ts"],"names":[],"mappings":";;AAEA,MAAM,IAAI,GAAoB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,EAAE,WAAW,EAAE,qCAAqC,EAAE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AI,CAAC,
|
|
1
|
+
{"version":3,"file":"naming-patterns.d.ts","sourceRoot":"","sources":["../../../src/plugin/rules/naming-patterns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAG9B,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAqBhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|