@effect/language-service 0.66.1 → 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.
@@ -4997,9 +4997,20 @@ var effectFnOpportunity = createDiagnostic({
4997
4997
  if (!traceName) return yield* TypeParserIssue.issue;
4998
4998
  const opportunity = yield* pipe(
4999
4999
  tryParseGenOpportunity(node),
5000
- orElse2(
5001
- () => succeed({ effectModuleName: sourceEffectModuleName, pipeArguments: [], generatorFunction: void 0 })
5002
- )
5000
+ orElse2(() => {
5001
+ if (ts.isArrowFunction(node) && !ts.isBlock(node.body)) {
5002
+ return TypeParserIssue.issue;
5003
+ }
5004
+ const body = ts.isArrowFunction(node) ? node.body : node.body;
5005
+ if (!body || !ts.isBlock(body) || body.statements.length <= 5) {
5006
+ return TypeParserIssue.issue;
5007
+ }
5008
+ return succeed({
5009
+ effectModuleName: sourceEffectModuleName,
5010
+ pipeArguments: [],
5011
+ generatorFunction: void 0
5012
+ });
5013
+ })
5003
5014
  );
5004
5015
  return {
5005
5016
  node,
@@ -5611,6 +5622,69 @@ var importFromBarrel = createDiagnostic({
5611
5622
  })
5612
5623
  });
5613
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
+
5614
5688
  // src/diagnostics/layerMergeAllWithDependencies.ts
5615
5689
  var layerMergeAllWithDependencies = createDiagnostic({
5616
5690
  name: "layerMergeAllWithDependencies",
@@ -5818,12 +5892,18 @@ var leakingRequirements = createDiagnostic({
5818
5892
  );
5819
5893
  function reportLeakingRequirements(node, requirements) {
5820
5894
  if (requirements.length === 0) return;
5895
+ const requirementsStr = requirements.map((_) => typeChecker.typeToString(_)).join(" | ");
5821
5896
  report({
5822
5897
  location: node,
5823
- messageText: `This Service is leaking the ${requirements.map((_) => typeChecker.typeToString(_)).join(" | ")} requirement.
5824
- If these requirements cannot be cached and are expected to be provided per method invocation (e.g. HttpServerRequest), you can either safely disable this diagnostic for this line through quickfixes or mark the service declaration with a JSDoc @effect-leakable-service.
5825
- Services should usually be collected in the layer creation body, and then provided at each method that requires them.
5826
- More info at https://effect.website/docs/requirements-management/layers/#avoiding-requirement-leakage`,
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`,
5827
5907
  fixes: []
5828
5908
  });
5829
5909
  }
@@ -9034,6 +9114,7 @@ var unsupportedServiceAccessors = createDiagnostic({
9034
9114
  // src/diagnostics.ts
9035
9115
  var diagnostics = [
9036
9116
  anyUnknownInErrorContext,
9117
+ instanceOfSchema,
9037
9118
  catchAllToMapError,
9038
9119
  catchUnfailableEffect,
9039
9120
  classSelfMismatch,