@effect/language-service 0.26.0 → 0.27.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/language-service",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "A Language-Service Plugin to Refactor and Diagnostic effect-ts projects",
5
5
  "main": "index.cjs",
6
6
  "bin": {
package/transform.js CHANGED
@@ -3481,6 +3481,73 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
3481
3481
  })
3482
3482
  });
3483
3483
 
3484
+ // src/diagnostics/strictBooleanExpressions.ts
3485
+ var strictBooleanExpressions = createDiagnostic({
3486
+ name: "strictBooleanExpressions",
3487
+ code: 17,
3488
+ severity: "off",
3489
+ apply: fn("strictBooleanExpressions.apply")(function* (sourceFile, report) {
3490
+ const ts = yield* service(TypeScriptApi);
3491
+ const typeChecker = yield* service(TypeCheckerApi);
3492
+ const conditionChecks = /* @__PURE__ */ new WeakMap();
3493
+ const nodeToVisit = [];
3494
+ const appendNodeToVisit = (node) => {
3495
+ nodeToVisit.push(node);
3496
+ return void 0;
3497
+ };
3498
+ ts.forEachChild(sourceFile, appendNodeToVisit);
3499
+ while (nodeToVisit.length > 0) {
3500
+ const node = nodeToVisit.shift();
3501
+ ts.forEachChild(node, appendNodeToVisit);
3502
+ const nodes = [];
3503
+ if (ts.isIfStatement(node)) {
3504
+ conditionChecks.set(node, true);
3505
+ nodes.push(node.expression);
3506
+ } else if (ts.isWhileStatement(node)) {
3507
+ conditionChecks.set(node, true);
3508
+ nodes.push(node.expression);
3509
+ } else if (ts.isConditionalExpression(node)) {
3510
+ conditionChecks.set(node, true);
3511
+ nodes.push(node.condition);
3512
+ } else if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.ExclamationToken) {
3513
+ conditionChecks.set(node, true);
3514
+ nodes.push(node.operand);
3515
+ } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.BarBarToken) {
3516
+ if (conditionChecks.has(node.parent)) conditionChecks.set(node, true);
3517
+ nodes.push(node.left);
3518
+ nodes.push(node.right);
3519
+ } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {
3520
+ if (conditionChecks.has(node.parent)) conditionChecks.set(node, true);
3521
+ nodes.push(node.left);
3522
+ nodes.push(node.right);
3523
+ }
3524
+ for (const nodeToCheck of nodes) {
3525
+ if (!nodeToCheck) continue;
3526
+ if (!conditionChecks.has(nodeToCheck.parent)) continue;
3527
+ const nodeType = typeChecker.getTypeAtLocation(nodeToCheck);
3528
+ const constrainedType = typeChecker.getBaseConstraintOfType(nodeType);
3529
+ let typesToCheck = [constrainedType || nodeType];
3530
+ while (typesToCheck.length > 0) {
3531
+ const type = typesToCheck.pop();
3532
+ if (type.isUnion()) {
3533
+ typesToCheck = typesToCheck.concat(type.types);
3534
+ continue;
3535
+ }
3536
+ if (type.flags & ts.TypeFlags.Boolean) continue;
3537
+ if (type.flags & ts.TypeFlags.Never) continue;
3538
+ if (type.flags & ts.TypeFlags.BooleanLiteral) continue;
3539
+ const typeName = typeChecker.typeToString(type);
3540
+ report({
3541
+ node: nodeToCheck,
3542
+ messageText: `Unexpected \`${typeName}\` type in condition, expected strictly a boolean instead.`,
3543
+ fixes: []
3544
+ });
3545
+ }
3546
+ }
3547
+ }
3548
+ })
3549
+ });
3550
+
3484
3551
  // src/diagnostics/tryCatchInEffectGen.ts
3485
3552
  var tryCatchInEffectGen = createDiagnostic({
3486
3553
  name: "tryCatchInEffectGen",
@@ -3705,7 +3772,8 @@ var diagnostics = [
3705
3772
  importFromBarrel,
3706
3773
  scopeInLayerEffect,
3707
3774
  effectInVoidSuccess,
3708
- unnecessaryPipeChain
3775
+ unnecessaryPipeChain,
3776
+ strictBooleanExpressions
3709
3777
  ];
3710
3778
 
3711
3779
  // src/transform.ts