@arnaud-barre/tsl-config 0.1.3 → 0.1.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/README.md +2 -0
- package/index.d.ts +2 -0
- package/index.js +35 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -135,6 +135,8 @@ export default defineConfig({
|
|
|
135
135
|
### Custom rules
|
|
136
136
|
|
|
137
137
|
- arrayCallbackReturn: Ensure array callbacks that require a return value (map, filter, find, some, ...) don't have undefined in their return type
|
|
138
|
+
- arrayNoEmptyVariadic: Disallow empty variadic arguments to array methods (push, unshift, concat)
|
|
138
139
|
- jsxFragmentCheckChildren: Validates that JSX shorthand fragment children match ReactNode type to workaround https://github.com/microsoft/TypeScript/issues/62358
|
|
139
140
|
- jsxKey: Validate JSX has key prop when in array or iterator
|
|
140
141
|
- jsxNoNumberTruthiness: Disallow `list.length && ...` in JSX
|
|
142
|
+
- typedEmptyArray: Ensure empty arrays declarations have an explicit type annotation
|
package/index.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ import * as tsl0 from "tsl";
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
declare const arnaudBarre: tsl0.RulesSet<{
|
|
5
5
|
arrayCallbackReturn: (options?: "off" | undefined) => tsl0.Rule<unknown>;
|
|
6
|
+
arrayNoEmptyVariadic: (options?: "off" | undefined) => tsl0.Rule<unknown>;
|
|
6
7
|
jsxFragmentCheckChildren: (options?: "off" | undefined) => tsl0.Rule<unknown>;
|
|
7
8
|
jsxKey: (options?: "off" | undefined) => tsl0.Rule<unknown>;
|
|
8
9
|
jsxNoNumberTruthiness: (options?: "off" | undefined) => tsl0.Rule<unknown>;
|
|
10
|
+
typedEmptyArray: (options?: "off" | undefined) => tsl0.Rule<unknown>;
|
|
9
11
|
}>;
|
|
10
12
|
declare const allRules: tsl0.Rule<unknown>[];
|
|
11
13
|
//#endregion
|
package/index.js
CHANGED
|
@@ -20,11 +20,11 @@ const methodsRecords = {
|
|
|
20
20
|
reduce: "addTypeAnnotation",
|
|
21
21
|
reduceRight: "addTypeAnnotation"
|
|
22
22
|
};
|
|
23
|
-
const methods = Object.keys(methodsRecords);
|
|
23
|
+
const methods$1 = Object.keys(methodsRecords);
|
|
24
24
|
const arrayCallbackReturn = defineRule(() => ({
|
|
25
25
|
name: "arnaudBarre/arrayCallbackReturn",
|
|
26
26
|
visitor: { PropertyAccessExpression(context, node) {
|
|
27
|
-
if (node.name.kind === SyntaxKind.Identifier && methods.includes(node.name.text) && node.parent.kind === SyntaxKind.CallExpression && node.parent.arguments.length >= 1) {
|
|
27
|
+
if (node.name.kind === SyntaxKind.Identifier && methods$1.includes(node.name.text) && node.parent.kind === SyntaxKind.CallExpression && node.parent.arguments.length >= 1) {
|
|
28
28
|
const callback = node.parent.arguments[0];
|
|
29
29
|
if (callback.kind === SyntaxKind.ArrowFunction && callback.body.kind !== SyntaxKind.Block) return;
|
|
30
30
|
const signatures = context.checker.getTypeAtLocation(callback).getCallSignatures();
|
|
@@ -44,6 +44,24 @@ const arrayCallbackReturn = defineRule(() => ({
|
|
|
44
44
|
} }
|
|
45
45
|
}));
|
|
46
46
|
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/rules/arrayNoEmptyVariadic.ts
|
|
49
|
+
const methods = [
|
|
50
|
+
"push",
|
|
51
|
+
"unshift",
|
|
52
|
+
"concat"
|
|
53
|
+
];
|
|
54
|
+
const arrayNoEmptyVariadic = defineRule(() => ({
|
|
55
|
+
name: "arnaudBarre/arrayNoEmptyVariadic",
|
|
56
|
+
visitor: { PropertyAccessExpression(context, node) {
|
|
57
|
+
if (node.name.kind === SyntaxKind.Identifier && methods.includes(node.name.text) && node.parent.kind === SyntaxKind.CallExpression && node.parent.arguments.length === 0) context.report({
|
|
58
|
+
start: node.name.getStart(),
|
|
59
|
+
end: node.parent.getEnd(),
|
|
60
|
+
message: "This call does nothing"
|
|
61
|
+
});
|
|
62
|
+
} }
|
|
63
|
+
}));
|
|
64
|
+
|
|
47
65
|
//#endregion
|
|
48
66
|
//#region src/rules/jsxFragmentCheckChildren.ts
|
|
49
67
|
const message$1 = "Children doesn't match ReactNode type. See https://github.com/microsoft/TypeScript/issues/62358";
|
|
@@ -228,13 +246,27 @@ const jsxNoNumberTruthiness = defineRule(() => ({
|
|
|
228
246
|
} }
|
|
229
247
|
}));
|
|
230
248
|
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/rules/typedEmptyArray.ts
|
|
251
|
+
const typedEmptyArray = defineRule(() => ({
|
|
252
|
+
name: "arnaudBarre/typedEmptyArray",
|
|
253
|
+
visitor: { VariableStatement(context, node) {
|
|
254
|
+
for (const declaration of node.declarationList.declarations) if (declaration.initializer && declaration.initializer.kind === SyntaxKind.ArrayLiteralExpression && declaration.initializer.elements.length === 0 && !declaration.type) context.report({
|
|
255
|
+
node: declaration.name,
|
|
256
|
+
message: "Empty array needs explicit type annotation"
|
|
257
|
+
});
|
|
258
|
+
} }
|
|
259
|
+
}));
|
|
260
|
+
|
|
231
261
|
//#endregion
|
|
232
262
|
//#region src/index.ts
|
|
233
263
|
const arnaudBarre = createRulesSet({
|
|
234
264
|
arrayCallbackReturn,
|
|
265
|
+
arrayNoEmptyVariadic,
|
|
235
266
|
jsxFragmentCheckChildren,
|
|
236
267
|
jsxKey,
|
|
237
|
-
jsxNoNumberTruthiness
|
|
268
|
+
jsxNoNumberTruthiness,
|
|
269
|
+
typedEmptyArray
|
|
238
270
|
});
|
|
239
271
|
const allRules = [
|
|
240
272
|
...core.all(),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arnaud-barre/tsl-config",
|
|
3
3
|
"description": "TS-React focused tsl configuration",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:ArnaudBarre/tsl-config",
|