@effect/language-service 0.67.0 → 0.68.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/README.md +1 -0
- package/cli.js +132 -11
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +74 -4
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +74 -4
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +74 -4
- package/transform.js.map +1 -1
|
@@ -5622,6 +5622,69 @@ var importFromBarrel = createDiagnostic({
|
|
|
5622
5622
|
})
|
|
5623
5623
|
});
|
|
5624
5624
|
|
|
5625
|
+
// src/diagnostics/instanceOfSchema.ts
|
|
5626
|
+
var instanceOfSchema = createDiagnostic({
|
|
5627
|
+
name: "instanceOfSchema",
|
|
5628
|
+
code: 45,
|
|
5629
|
+
description: "Suggests using Schema.is instead of instanceof for Effect Schema types",
|
|
5630
|
+
severity: "off",
|
|
5631
|
+
apply: fn("instanceOfSchema.apply")(function* (sourceFile, report) {
|
|
5632
|
+
const ts = yield* service(TypeScriptApi);
|
|
5633
|
+
const typeParser = yield* service(TypeParser);
|
|
5634
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
5635
|
+
const nodeToVisit = [];
|
|
5636
|
+
const appendNodeToVisit = (node) => {
|
|
5637
|
+
nodeToVisit.push(node);
|
|
5638
|
+
return void 0;
|
|
5639
|
+
};
|
|
5640
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
5641
|
+
while (nodeToVisit.length > 0) {
|
|
5642
|
+
const node = nodeToVisit.shift();
|
|
5643
|
+
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.InstanceOfKeyword) {
|
|
5644
|
+
const leftExpr = node.left;
|
|
5645
|
+
const rightExpr = node.right;
|
|
5646
|
+
const rightType = typeCheckerUtils.getTypeAtLocation(rightExpr);
|
|
5647
|
+
if (!rightType) {
|
|
5648
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
5649
|
+
continue;
|
|
5650
|
+
}
|
|
5651
|
+
const isSchemaType = yield* pipe(
|
|
5652
|
+
typeParser.effectSchemaType(rightType, rightExpr),
|
|
5653
|
+
option
|
|
5654
|
+
);
|
|
5655
|
+
if (isSchemaType._tag === "Some") {
|
|
5656
|
+
report({
|
|
5657
|
+
location: node,
|
|
5658
|
+
messageText: "Consider using Schema.is instead of instanceof for Effect Schema types.",
|
|
5659
|
+
fixes: [{
|
|
5660
|
+
fixName: "instanceOfSchema_fix",
|
|
5661
|
+
description: "Replace with Schema.is",
|
|
5662
|
+
apply: gen(function* () {
|
|
5663
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
5664
|
+
const schemaIsCall = ts.factory.createCallExpression(
|
|
5665
|
+
ts.factory.createPropertyAccessExpression(
|
|
5666
|
+
ts.factory.createIdentifier("Schema"),
|
|
5667
|
+
"is"
|
|
5668
|
+
),
|
|
5669
|
+
void 0,
|
|
5670
|
+
[rightExpr]
|
|
5671
|
+
);
|
|
5672
|
+
const fullCall = ts.factory.createCallExpression(
|
|
5673
|
+
schemaIsCall,
|
|
5674
|
+
void 0,
|
|
5675
|
+
[leftExpr]
|
|
5676
|
+
);
|
|
5677
|
+
changeTracker.replaceNode(sourceFile, node, fullCall);
|
|
5678
|
+
})
|
|
5679
|
+
}]
|
|
5680
|
+
});
|
|
5681
|
+
}
|
|
5682
|
+
}
|
|
5683
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
5684
|
+
}
|
|
5685
|
+
})
|
|
5686
|
+
});
|
|
5687
|
+
|
|
5625
5688
|
// src/diagnostics/layerMergeAllWithDependencies.ts
|
|
5626
5689
|
var layerMergeAllWithDependencies = createDiagnostic({
|
|
5627
5690
|
name: "layerMergeAllWithDependencies",
|
|
@@ -5829,12 +5892,18 @@ var leakingRequirements = createDiagnostic({
|
|
|
5829
5892
|
);
|
|
5830
5893
|
function reportLeakingRequirements(node, requirements) {
|
|
5831
5894
|
if (requirements.length === 0) return;
|
|
5895
|
+
const requirementsStr = requirements.map((_) => typeChecker.typeToString(_)).join(" | ");
|
|
5832
5896
|
report({
|
|
5833
5897
|
location: node,
|
|
5834
|
-
messageText: `
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5898
|
+
messageText: `Methods of this Service require \`${requirementsStr}\` from every caller.
|
|
5899
|
+
|
|
5900
|
+
This leaks implementation details into the service's public type \u2014 callers shouldn't need to know *how* the service works internally, only *what* it provides.
|
|
5901
|
+
|
|
5902
|
+
Resolve these dependencies at Layer creation and provide them to each method, so the service's type reflects its purpose, not its implementation.
|
|
5903
|
+
|
|
5904
|
+
To suppress this diagnostic for specific dependency types that are intentionally passed through (e.g., HttpServerRequest), add \`@effect-leakable-service\` JSDoc to their interface declarations (e.g., the \`${typeChecker.typeToString(requirements[0])}\` interface), not to this service.
|
|
5905
|
+
|
|
5906
|
+
More info and examples at https://effect.website/docs/requirements-management/layers/#avoiding-requirement-leakage`,
|
|
5838
5907
|
fixes: []
|
|
5839
5908
|
});
|
|
5840
5909
|
}
|
|
@@ -9045,6 +9114,7 @@ var unsupportedServiceAccessors = createDiagnostic({
|
|
|
9045
9114
|
// src/diagnostics.ts
|
|
9046
9115
|
var diagnostics = [
|
|
9047
9116
|
anyUnknownInErrorContext,
|
|
9117
|
+
instanceOfSchema,
|
|
9048
9118
|
catchAllToMapError,
|
|
9049
9119
|
catchUnfailableEffect,
|
|
9050
9120
|
classSelfMismatch,
|