@effect/language-service 0.26.0 → 0.27.1

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.1",
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
@@ -1355,7 +1355,11 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1355
1355
  const diagnostics2 = [];
1356
1356
  const codeFixes = [];
1357
1357
  const ruleNameLowered = rule.name.toLowerCase();
1358
+ const defaultLevel = pluginOptions.diagnosticSeverity[ruleNameLowered] || rule.severity;
1358
1359
  if (skippedRules.indexOf(ruleNameLowered) > -1) return { diagnostics: diagnostics2, codeFixes };
1360
+ if (defaultLevel === "off" && (lineOverrides[ruleNameLowered] || sectionOverrides[ruleNameLowered] || []).length === 0) {
1361
+ return { diagnostics: diagnostics2, codeFixes };
1362
+ }
1359
1363
  const fixByDisableNextLine = (_) => ({
1360
1364
  fixName: rule.name + "_skipNextLine",
1361
1365
  description: "Disable " + rule.name + " for this line",
@@ -1396,7 +1400,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
1396
1400
  });
1397
1401
  });
1398
1402
  for (const emitted of applicableDiagnostics.slice(0)) {
1399
- let newLevel = pluginOptions.diagnosticSeverity[ruleNameLowered] || rule.severity;
1403
+ let newLevel = defaultLevel;
1400
1404
  const lineOverride = (lineOverrides[ruleNameLowered] || []).find(
1401
1405
  (_) => _.pos < emitted.node.getStart(sourceFile) && _.end >= emitted.node.getEnd()
1402
1406
  );
@@ -3481,6 +3485,73 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
3481
3485
  })
3482
3486
  });
3483
3487
 
3488
+ // src/diagnostics/strictBooleanExpressions.ts
3489
+ var strictBooleanExpressions = createDiagnostic({
3490
+ name: "strictBooleanExpressions",
3491
+ code: 17,
3492
+ severity: "off",
3493
+ apply: fn("strictBooleanExpressions.apply")(function* (sourceFile, report) {
3494
+ const ts = yield* service(TypeScriptApi);
3495
+ const typeChecker = yield* service(TypeCheckerApi);
3496
+ const conditionChecks = /* @__PURE__ */ new WeakMap();
3497
+ const nodeToVisit = [];
3498
+ const appendNodeToVisit = (node) => {
3499
+ nodeToVisit.push(node);
3500
+ return void 0;
3501
+ };
3502
+ ts.forEachChild(sourceFile, appendNodeToVisit);
3503
+ while (nodeToVisit.length > 0) {
3504
+ const node = nodeToVisit.shift();
3505
+ ts.forEachChild(node, appendNodeToVisit);
3506
+ const nodes = [];
3507
+ if (ts.isIfStatement(node)) {
3508
+ conditionChecks.set(node, true);
3509
+ nodes.push(node.expression);
3510
+ } else if (ts.isWhileStatement(node)) {
3511
+ conditionChecks.set(node, true);
3512
+ nodes.push(node.expression);
3513
+ } else if (ts.isConditionalExpression(node)) {
3514
+ conditionChecks.set(node, true);
3515
+ nodes.push(node.condition);
3516
+ } else if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.ExclamationToken) {
3517
+ conditionChecks.set(node, true);
3518
+ nodes.push(node.operand);
3519
+ } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.BarBarToken) {
3520
+ if (conditionChecks.has(node.parent)) conditionChecks.set(node, true);
3521
+ nodes.push(node.left);
3522
+ nodes.push(node.right);
3523
+ } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {
3524
+ if (conditionChecks.has(node.parent)) conditionChecks.set(node, true);
3525
+ nodes.push(node.left);
3526
+ nodes.push(node.right);
3527
+ }
3528
+ for (const nodeToCheck of nodes) {
3529
+ if (!nodeToCheck) continue;
3530
+ if (!conditionChecks.has(nodeToCheck.parent)) continue;
3531
+ const nodeType = typeChecker.getTypeAtLocation(nodeToCheck);
3532
+ const constrainedType = typeChecker.getBaseConstraintOfType(nodeType);
3533
+ let typesToCheck = [constrainedType || nodeType];
3534
+ while (typesToCheck.length > 0) {
3535
+ const type = typesToCheck.pop();
3536
+ if (type.isUnion()) {
3537
+ typesToCheck = typesToCheck.concat(type.types);
3538
+ continue;
3539
+ }
3540
+ if (type.flags & ts.TypeFlags.Boolean) continue;
3541
+ if (type.flags & ts.TypeFlags.Never) continue;
3542
+ if (type.flags & ts.TypeFlags.BooleanLiteral) continue;
3543
+ const typeName = typeChecker.typeToString(type);
3544
+ report({
3545
+ node: nodeToCheck,
3546
+ messageText: `Unexpected \`${typeName}\` type in condition, expected strictly a boolean instead.`,
3547
+ fixes: []
3548
+ });
3549
+ }
3550
+ }
3551
+ }
3552
+ })
3553
+ });
3554
+
3484
3555
  // src/diagnostics/tryCatchInEffectGen.ts
3485
3556
  var tryCatchInEffectGen = createDiagnostic({
3486
3557
  name: "tryCatchInEffectGen",
@@ -3705,7 +3776,8 @@ var diagnostics = [
3705
3776
  importFromBarrel,
3706
3777
  scopeInLayerEffect,
3707
3778
  effectInVoidSuccess,
3708
- unnecessaryPipeChain
3779
+ unnecessaryPipeChain,
3780
+ strictBooleanExpressions
3709
3781
  ];
3710
3782
 
3711
3783
  // src/transform.ts