@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/cli.js +69 -1
- package/cli.js.map +1 -1
- package/index.js +69 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +69 -1
- package/transform.js.map +1 -1
package/index.js
CHANGED
|
@@ -3608,6 +3608,73 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
|
|
|
3608
3608
|
})
|
|
3609
3609
|
});
|
|
3610
3610
|
|
|
3611
|
+
// src/diagnostics/strictBooleanExpressions.ts
|
|
3612
|
+
var strictBooleanExpressions = createDiagnostic({
|
|
3613
|
+
name: "strictBooleanExpressions",
|
|
3614
|
+
code: 17,
|
|
3615
|
+
severity: "off",
|
|
3616
|
+
apply: fn("strictBooleanExpressions.apply")(function* (sourceFile, report) {
|
|
3617
|
+
const ts = yield* service(TypeScriptApi);
|
|
3618
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
3619
|
+
const conditionChecks = /* @__PURE__ */ new WeakMap();
|
|
3620
|
+
const nodeToVisit = [];
|
|
3621
|
+
const appendNodeToVisit = (node) => {
|
|
3622
|
+
nodeToVisit.push(node);
|
|
3623
|
+
return void 0;
|
|
3624
|
+
};
|
|
3625
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
3626
|
+
while (nodeToVisit.length > 0) {
|
|
3627
|
+
const node = nodeToVisit.shift();
|
|
3628
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
3629
|
+
const nodes = [];
|
|
3630
|
+
if (ts.isIfStatement(node)) {
|
|
3631
|
+
conditionChecks.set(node, true);
|
|
3632
|
+
nodes.push(node.expression);
|
|
3633
|
+
} else if (ts.isWhileStatement(node)) {
|
|
3634
|
+
conditionChecks.set(node, true);
|
|
3635
|
+
nodes.push(node.expression);
|
|
3636
|
+
} else if (ts.isConditionalExpression(node)) {
|
|
3637
|
+
conditionChecks.set(node, true);
|
|
3638
|
+
nodes.push(node.condition);
|
|
3639
|
+
} else if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.ExclamationToken) {
|
|
3640
|
+
conditionChecks.set(node, true);
|
|
3641
|
+
nodes.push(node.operand);
|
|
3642
|
+
} else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.BarBarToken) {
|
|
3643
|
+
if (conditionChecks.has(node.parent)) conditionChecks.set(node, true);
|
|
3644
|
+
nodes.push(node.left);
|
|
3645
|
+
nodes.push(node.right);
|
|
3646
|
+
} else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {
|
|
3647
|
+
if (conditionChecks.has(node.parent)) conditionChecks.set(node, true);
|
|
3648
|
+
nodes.push(node.left);
|
|
3649
|
+
nodes.push(node.right);
|
|
3650
|
+
}
|
|
3651
|
+
for (const nodeToCheck of nodes) {
|
|
3652
|
+
if (!nodeToCheck) continue;
|
|
3653
|
+
if (!conditionChecks.has(nodeToCheck.parent)) continue;
|
|
3654
|
+
const nodeType = typeChecker.getTypeAtLocation(nodeToCheck);
|
|
3655
|
+
const constrainedType = typeChecker.getBaseConstraintOfType(nodeType);
|
|
3656
|
+
let typesToCheck = [constrainedType || nodeType];
|
|
3657
|
+
while (typesToCheck.length > 0) {
|
|
3658
|
+
const type = typesToCheck.pop();
|
|
3659
|
+
if (type.isUnion()) {
|
|
3660
|
+
typesToCheck = typesToCheck.concat(type.types);
|
|
3661
|
+
continue;
|
|
3662
|
+
}
|
|
3663
|
+
if (type.flags & ts.TypeFlags.Boolean) continue;
|
|
3664
|
+
if (type.flags & ts.TypeFlags.Never) continue;
|
|
3665
|
+
if (type.flags & ts.TypeFlags.BooleanLiteral) continue;
|
|
3666
|
+
const typeName = typeChecker.typeToString(type);
|
|
3667
|
+
report({
|
|
3668
|
+
node: nodeToCheck,
|
|
3669
|
+
messageText: `Unexpected \`${typeName}\` type in condition, expected strictly a boolean instead.`,
|
|
3670
|
+
fixes: []
|
|
3671
|
+
});
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
})
|
|
3676
|
+
});
|
|
3677
|
+
|
|
3611
3678
|
// src/diagnostics/tryCatchInEffectGen.ts
|
|
3612
3679
|
var tryCatchInEffectGen = createDiagnostic({
|
|
3613
3680
|
name: "tryCatchInEffectGen",
|
|
@@ -3832,7 +3899,8 @@ var diagnostics = [
|
|
|
3832
3899
|
importFromBarrel,
|
|
3833
3900
|
scopeInLayerEffect,
|
|
3834
3901
|
effectInVoidSuccess,
|
|
3835
|
-
unnecessaryPipeChain
|
|
3902
|
+
unnecessaryPipeChain,
|
|
3903
|
+
strictBooleanExpressions
|
|
3836
3904
|
];
|
|
3837
3905
|
|
|
3838
3906
|
// src/completions/effectDiagnosticsComment.ts
|