@effect/language-service 0.69.2 → 0.70.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 CHANGED
@@ -78,7 +78,7 @@ And you're done! You'll now be able to use a set of refactors and diagnostics th
78
78
  - Warn when using `Schema.Union` with multiple `Schema.Literal` calls that can be simplified to a single `Schema.Literal` call
79
79
  - Suggest using `Schema.TaggedStruct` instead of `Schema.Struct` when a `_tag` field with `Schema.Literal` is present to make the tag optional in the constructor
80
80
  - Warn when using `yield* Effect.fail()` with yieldable error types that can be yielded directly
81
- - Warn when using `Effect.fail` with the global `Error` type, recommending tagged errors
81
+ - Warn when the global `Error` type is used in an Effect failure channel, recommending tagged errors
82
82
  - Warn when `Layer.mergeAll` contains layers with interdependencies (where one layer provides a service that another layer in the same call requires)
83
83
  - Suggest using `Effect.fn` for functions that return `Effect.gen` for better tracing and concise syntax
84
84
  - Warn when `Effect.fn` or `Effect.fnUntraced` is used as an IIFE (Immediately Invoked Function Expression), suggesting `Effect.gen` instead
package/cli.js CHANGED
@@ -30214,7 +30214,7 @@ var runMain3 = runMain2;
30214
30214
  // package.json
30215
30215
  var package_default = {
30216
30216
  name: "@effect/language-service",
30217
- version: "0.69.2",
30217
+ version: "0.70.0",
30218
30218
  packageManager: "pnpm@8.11.0",
30219
30219
  publishConfig: {
30220
30220
  access: "public",
@@ -37060,7 +37060,7 @@ Instead, use tagged errors or custom errors with a discriminator property to get
37060
37060
  var globalErrorInEffectFailure = createDiagnostic({
37061
37061
  name: "globalErrorInEffectFailure",
37062
37062
  code: 35,
37063
- description: "Warns when Effect.fail is called with the global Error type",
37063
+ description: "Warns when the global Error type is used in an Effect failure channel",
37064
37064
  severity: "warning",
37065
37065
  apply: fn2("globalErrorInEffectFailure.apply")(function* (sourceFile, report) {
37066
37066
  const ts = yield* service2(TypeScriptApi);
@@ -37075,27 +37075,35 @@ var globalErrorInEffectFailure = createDiagnostic({
37075
37075
  while (nodeToVisit.length > 0) {
37076
37076
  const node = nodeToVisit.shift();
37077
37077
  ts.forEachChild(node, appendNodeToVisit);
37078
- if (ts.isCallExpression(node)) {
37079
- yield* pipe(
37080
- typeParser.isNodeReferenceToEffectModuleApi("fail")(node.expression),
37081
- flatMap18(() => {
37082
- if (node.arguments.length > 0) {
37083
- const failArgument = node.arguments[0];
37084
- const argumentType = typeCheckerUtils.getTypeAtLocation(failArgument);
37085
- if (argumentType && typeCheckerUtils.isGlobalErrorType(argumentType)) {
37086
- return sync11(
37087
- () => report({
37088
- location: node,
37089
- messageText: `Effect.fail is called with the global Error type. It's not recommended to use the global Error type in Effect failures as they can get merged together. Instead, use tagged errors or custom errors with a discriminator property to get properly type-checked errors.`,
37090
- fixes: []
37091
- })
37092
- );
37078
+ if (ts.isNewExpression(node)) {
37079
+ const newExpressionType = typeCheckerUtils.getTypeAtLocation(node);
37080
+ if (!newExpressionType || !typeCheckerUtils.isGlobalErrorType(newExpressionType)) {
37081
+ continue;
37082
+ }
37083
+ let current = node.parent;
37084
+ while (current) {
37085
+ const currentType = typeCheckerUtils.getTypeAtLocation(current);
37086
+ if (currentType) {
37087
+ const effectTypeResult = yield* pipe(
37088
+ typeParser.effectType(currentType, current),
37089
+ option5
37090
+ );
37091
+ if (effectTypeResult._tag === "Some") {
37092
+ const effectType = effectTypeResult.value;
37093
+ const failureMembers = typeCheckerUtils.unrollUnionMembers(effectType.E);
37094
+ const hasGlobalError = failureMembers.some((member) => typeCheckerUtils.isGlobalErrorType(member));
37095
+ if (hasGlobalError) {
37096
+ report({
37097
+ location: node,
37098
+ messageText: `The global Error type is used in an Effect failure channel. It's not recommended to use the global Error type in Effect failures as they can get merged together. Instead, use tagged errors or custom errors with a discriminator property to get properly type-checked errors.`,
37099
+ fixes: []
37100
+ });
37093
37101
  }
37102
+ break;
37094
37103
  }
37095
- return void_8;
37096
- }),
37097
- ignore3
37098
- );
37104
+ }
37105
+ current = current.parent;
37106
+ }
37099
37107
  }
37100
37108
  }
37101
37109
  })
@@ -37684,9 +37692,29 @@ var missedPipeableOpportunity = createDiagnostic({
37684
37692
  transformations: flow2.transformations.slice(0, firstPipeableIndex)
37685
37693
  });
37686
37694
  const afterTransformations = flow2.transformations.slice(pipeableEndIndex);
37695
+ const getOriginalSubjectNode = () => {
37696
+ if (firstPipeableIndex === 0) {
37697
+ return flow2.subject.node;
37698
+ }
37699
+ let current = flow2.node;
37700
+ for (let i = flow2.transformations.length; i > firstPipeableIndex; i--) {
37701
+ const t = flow2.transformations[i - 1];
37702
+ if (t.kind === "call" && ts.isCallExpression(current) && current.arguments.length > 0) {
37703
+ current = current.arguments[0];
37704
+ } else {
37705
+ return void 0;
37706
+ }
37707
+ }
37708
+ return current;
37709
+ };
37710
+ const originalSubjectNode = getOriginalSubjectNode();
37711
+ const subjectText = originalSubjectNode ? sourceFile.text.slice(
37712
+ ts.getTokenPosOfNode(originalSubjectNode, sourceFile),
37713
+ originalSubjectNode.end
37714
+ ).trim() : "";
37687
37715
  report({
37688
37716
  location: flow2.node,
37689
- messageText: `Nested function calls can be converted to pipeable style for better readability.`,
37717
+ messageText: `Nested function calls can be converted to pipeable style for better readability; consider using ${subjectText}.pipe(...) instead.`,
37690
37718
  fixes: [{
37691
37719
  fixName: "missedPipeableOpportunity_fix",
37692
37720
  description: "Convert to pipe style",