@arnaud-barre/tsl-config 0.1.4 → 0.1.5

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 CHANGED
@@ -25,7 +25,7 @@ export default defineConfig({
25
25
  }
26
26
  ```
27
27
 
28
- ## TS config (5.9)
28
+ ## TS config (6.0)
29
29
 
30
30
  ### Web project
31
31
 
@@ -37,7 +37,7 @@ export default defineConfig({
37
37
  "jsx": "react-jsx",
38
38
  "module": "ESNext",
39
39
  "moduleDetection": "force",
40
- "lib": ["ES2022", "DOM", "DOM.Iterable"],
40
+ "lib": ["ES2022", "DOM"],
41
41
  "types": ["vite/client", "tsl/patches"],
42
42
  "skipLibCheck": true,
43
43
 
@@ -49,12 +49,10 @@ export default defineConfig({
49
49
  "noEmit": true,
50
50
 
51
51
  /* Linting */
52
- "strict": true,
53
52
  "noUnusedLocals": true,
54
53
  "noUnusedParameters": true,
55
54
  "noFallthroughCasesInSwitch": true,
56
55
  "useUnknownInCatchVariables": true,
57
- "noUncheckedSideEffectImports": true,
58
56
  "noPropertyAccessFromIndexSignature": true,
59
57
 
60
58
  "plugins": [{ "name": "tsl/plugin" }]
package/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import * as tsl0 from "tsl";
1
+ import * as _$tsl from "tsl";
2
2
 
3
3
  //#region src/index.d.ts
4
- declare const arnaudBarre: tsl0.RulesSet<{
5
- arrayCallbackReturn: (options?: "off" | undefined) => tsl0.Rule<unknown>;
6
- arrayNoEmptyVariadic: (options?: "off" | undefined) => tsl0.Rule<unknown>;
7
- jsxFragmentCheckChildren: (options?: "off" | undefined) => tsl0.Rule<unknown>;
8
- jsxKey: (options?: "off" | undefined) => tsl0.Rule<unknown>;
9
- jsxNoNumberTruthiness: (options?: "off" | undefined) => tsl0.Rule<unknown>;
10
- typedEmptyArray: (options?: "off" | undefined) => tsl0.Rule<unknown>;
4
+ declare const arnaudBarre: _$tsl.RulesSet<{
5
+ arrayCallbackReturn: (options?: "off" | undefined) => _$tsl.Rule<unknown>;
6
+ arrayNoEmptyVariadic: (options?: "off" | undefined) => _$tsl.Rule<unknown>;
7
+ jsxFragmentCheckChildren: (options?: "off" | undefined) => _$tsl.Rule<unknown>;
8
+ jsxKey: (options?: "off" | undefined) => _$tsl.Rule<unknown>;
9
+ jsxNoNumberTruthiness: (options?: "off" | undefined) => _$tsl.Rule<unknown>;
10
+ typedEmptyArray: (options?: "off" | undefined) => _$tsl.Rule<unknown>;
11
11
  }>;
12
- declare const allRules: tsl0.Rule<unknown>[];
12
+ declare const allRules: _$tsl.Rule<unknown>[];
13
13
  //#endregion
14
14
  export { allRules, arnaudBarre };
package/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { core, createRulesSet, defineRule } from "tsl";
2
2
  import { JsxEmit, SyntaxKind, TypeFlags } from "typescript";
3
-
4
3
  //#region src/rules/arrayCallbackReturn.ts
5
4
  const base = "Found undefined in the return type of this callback. It could come from a missing return statement.";
6
5
  const messages$1 = {
@@ -43,7 +42,6 @@ const arrayCallbackReturn = defineRule(() => ({
43
42
  }
44
43
  } }
45
44
  }));
46
-
47
45
  //#endregion
48
46
  //#region src/rules/arrayNoEmptyVariadic.ts
49
47
  const methods = [
@@ -61,7 +59,6 @@ const arrayNoEmptyVariadic = defineRule(() => ({
61
59
  });
62
60
  } }
63
61
  }));
64
-
65
62
  //#endregion
66
63
  //#region src/rules/jsxFragmentCheckChildren.ts
67
64
  const message$1 = "Children doesn't match ReactNode type. See https://github.com/microsoft/TypeScript/issues/62358";
@@ -94,17 +91,14 @@ function getReactNodeSymbol(program) {
94
91
  if (weekMap.has(program)) return weekMap.get(program);
95
92
  const reactSourceFile = program.getSourceFiles().find((sf) => sf.fileName.includes("@types/react/index.d.ts"));
96
93
  if (!reactSourceFile) return;
97
- const namespace = reactSourceFile.statements.find((s) => s.kind === SyntaxKind.ModuleDeclaration);
98
- if (!namespace) return;
99
- if (namespace.body?.kind !== SyntaxKind.ModuleBlock) return;
100
- const statement = namespace.body.statements.find((s) => s.kind === SyntaxKind.TypeAliasDeclaration && s.name.getText() === "ReactNode");
101
- if (!statement) return;
102
- const symbol = program.getTypeChecker().getSymbolAtLocation(statement.name);
94
+ const checker = program.getTypeChecker();
95
+ const modSymbol = checker.getSymbolAtLocation(reactSourceFile);
96
+ if (!modSymbol) return;
97
+ const symbol = checker.getExportsOfModule(modSymbol).find((e) => e.getName() === "ReactNode");
103
98
  if (!symbol) return;
104
99
  weekMap.set(program, symbol);
105
100
  return symbol;
106
101
  }
107
-
108
102
  //#endregion
109
103
  //#region src/rules/jsxKey.ts
110
104
  const reactComponentNameRE = /^[A-Z][a-zA-Z0-9]*$/u;
@@ -165,6 +159,13 @@ const jsxKey = defineRule(() => {
165
159
  checkExpression(node.left, context);
166
160
  checkExpression(node.right, context);
167
161
  break;
162
+ case SyntaxKind.ParenthesizedExpression:
163
+ case SyntaxKind.SatisfiesExpression:
164
+ case SyntaxKind.TypeAssertionExpression:
165
+ case SyntaxKind.NonNullExpression:
166
+ case SyntaxKind.AsExpression:
167
+ checkExpression(node.expression, context);
168
+ break;
168
169
  default: break;
169
170
  }
170
171
  };
@@ -229,35 +230,9 @@ const jsxKey = defineRule(() => {
229
230
  }
230
231
  };
231
232
  });
232
-
233
233
  //#endregion
234
234
  //#region src/rules/jsxNoNumberTruthiness.ts
235
235
  const message = "Don't use logical expression on a number inside JSX, you might render the character 0 instead of rendering nothing. Either use a ternary expression or more explicit condition";
236
- const jsxNoNumberTruthiness = defineRule(() => ({
237
- name: "arnaudBarre/jsxNoNumberTruthiness",
238
- visitor: { BinaryExpression(context, node) {
239
- if (node.operatorToken.kind !== SyntaxKind.AmpersandAmpersandToken) return;
240
- if (node.parent.kind !== SyntaxKind.JsxExpression) return;
241
- const type = context.checker.getTypeAtLocation(node.left);
242
- if (context.utils.typeOrUnionHasFlag(type, TypeFlags.NumberLike)) context.report({
243
- node,
244
- message
245
- });
246
- } }
247
- }));
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
-
261
236
  //#endregion
262
237
  //#region src/index.ts
263
238
  const arnaudBarre = createRulesSet({
@@ -265,8 +240,27 @@ const arnaudBarre = createRulesSet({
265
240
  arrayNoEmptyVariadic,
266
241
  jsxFragmentCheckChildren,
267
242
  jsxKey,
268
- jsxNoNumberTruthiness,
269
- typedEmptyArray
243
+ jsxNoNumberTruthiness: defineRule(() => ({
244
+ name: "arnaudBarre/jsxNoNumberTruthiness",
245
+ visitor: { BinaryExpression(context, node) {
246
+ if (node.operatorToken.kind !== SyntaxKind.AmpersandAmpersandToken) return;
247
+ if (node.parent.kind !== SyntaxKind.JsxExpression) return;
248
+ const type = context.checker.getTypeAtLocation(node.left);
249
+ if (context.utils.typeOrUnionHasFlag(type, TypeFlags.NumberLike)) context.report({
250
+ node,
251
+ message
252
+ });
253
+ } }
254
+ })),
255
+ typedEmptyArray: defineRule(() => ({
256
+ name: "arnaudBarre/typedEmptyArray",
257
+ visitor: { VariableStatement(context, node) {
258
+ for (const declaration of node.declarationList.declarations) if (declaration.initializer && declaration.initializer.kind === SyntaxKind.ArrayLiteralExpression && declaration.initializer.elements.length === 0 && !declaration.type) context.report({
259
+ node: declaration.name,
260
+ message: "Empty array needs explicit type annotation"
261
+ });
262
+ } }
263
+ }))
270
264
  });
271
265
  const allRules = [
272
266
  ...core.all(),
@@ -299,6 +293,5 @@ const allRules = [
299
293
  }),
300
294
  ...arnaudBarre.all()
301
295
  ];
302
-
303
296
  //#endregion
304
- export { allRules, arnaudBarre };
297
+ export { allRules, arnaudBarre };
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",
4
+ "version": "0.1.5",
5
5
  "author": "Arnaud Barré (https://github.com/ArnaudBarre)",
6
6
  "license": "MIT",
7
7
  "repository": "github:ArnaudBarre/tsl-config",
@@ -10,7 +10,7 @@
10
10
  ".": "./index.js"
11
11
  },
12
12
  "peerDependencies": {
13
- "tsl": "^1.0.22",
14
- "typescript": "~5.9"
13
+ "tsl": "^1.0.30",
14
+ "typescript": "~6.0"
15
15
  }
16
16
  }