tsl-dx 0.5.2 → 0.5.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.
Files changed (2) hide show
  1. package/dist/index.js +21 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -303,8 +303,9 @@ const nullish = defineRule((options) => ({
303
303
  return { runtimeLibrary: options?.runtimeLibrary ?? "@local/eff" };
304
304
  },
305
305
  visitor: {
306
- UndefinedKeyword(ctx, node) {
306
+ Identifier(ctx, node) {
307
307
  if (node.getSourceFile().isDeclarationFile) return;
308
+ if (node.parent.kind === SyntaxKind.BinaryExpression || node.text !== "undefined") return;
308
309
  ctx.report({
309
310
  node,
310
311
  message: messages.useUnitForUndefined,
@@ -321,6 +322,24 @@ const nullish = defineRule((options) => ({
321
322
  }]
322
323
  });
323
324
  },
325
+ UndefinedKeyword(ctx, node) {
326
+ if (node.getSourceFile().isDeclarationFile) return;
327
+ ctx.report({
328
+ node,
329
+ message: messages.useUnitForUndefined,
330
+ suggestions: [{
331
+ message: suggestions.replaceWithExpression({ expr: "unit" }),
332
+ changes: [{
333
+ node,
334
+ newText: "unit"
335
+ }, {
336
+ start: 0,
337
+ end: 0,
338
+ newText: `import type { unit } from '${ctx.data.runtimeLibrary}';\n`
339
+ }]
340
+ }]
341
+ });
342
+ },
324
343
  BinaryExpression(ctx, node) {
325
344
  if (node.getSourceFile().isDeclarationFile) return;
326
345
  const newOperatorText = match(node.operatorToken.kind).with(SyntaxKind.EqualsEqualsEqualsToken, () => "==").with(SyntaxKind.ExclamationEqualsEqualsToken, () => "!=").otherwise(() => null);
@@ -328,7 +347,7 @@ const nullish = defineRule((options) => ({
328
347
  const offendingChild = [node.left, node.right].find((n) => {
329
348
  switch (n.kind) {
330
349
  case SyntaxKind.NullKeyword: return true;
331
- case SyntaxKind.Identifier: return n.escapedText === "undefined";
350
+ case SyntaxKind.Identifier: return n.text === "unit" || n.text === "undefined";
332
351
  default: return false;
333
352
  }
334
353
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsl-dx",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "A tsl plugin for better JavaScript/TypeScript DX.",
5
5
  "keywords": [
6
6
  "tsl",