@effect/language-service 0.84.3 → 0.85.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.
@@ -27,7 +27,7 @@ __export(effect_lsp_patch_utils_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(effect_lsp_patch_utils_exports);
29
29
 
30
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Pipeable.js
30
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Pipeable.js
31
31
  var pipeArguments = (self, args3) => {
32
32
  switch (args3.length) {
33
33
  case 0:
@@ -60,7 +60,7 @@ var pipeArguments = (self, args3) => {
60
60
  }
61
61
  };
62
62
 
63
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Function.js
63
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Function.js
64
64
  var dual = function(arity, body) {
65
65
  if (typeof arity === "function") {
66
66
  return function() {
@@ -108,7 +108,7 @@ function pipe(a, ...args3) {
108
108
  return pipeArguments(a, args3);
109
109
  }
110
110
 
111
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/internal/equal.js
111
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/internal/equal.js
112
112
  var getAllObjectKeys = (obj) => {
113
113
  const keys2 = new Set(Reflect.ownKeys(obj));
114
114
  if (obj.constructor === Object) return keys2;
@@ -131,7 +131,7 @@ var getAllObjectKeys = (obj) => {
131
131
  };
132
132
  var byReferenceInstances = /* @__PURE__ */ new WeakSet();
133
133
 
134
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Predicate.js
134
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Predicate.js
135
135
  function isString(input) {
136
136
  return typeof input === "string";
137
137
  }
@@ -152,7 +152,7 @@ function isObjectKeyword(input) {
152
152
  }
153
153
  var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObjectKeyword(self) && property in self);
154
154
 
155
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Hash.js
155
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Hash.js
156
156
  var symbol = "~effect/interfaces/Hash";
157
157
  var hash = (self) => {
158
158
  switch (typeof self) {
@@ -271,7 +271,7 @@ function withVisitedTracking(obj, fn2) {
271
271
  return result;
272
272
  }
273
273
 
274
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Equal.js
274
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Equal.js
275
275
  var symbol2 = "~effect/interfaces/Equal";
276
276
  function equals() {
277
277
  if (arguments.length === 1) {
@@ -433,10 +433,10 @@ var compareSets = /* @__PURE__ */ makeCompareSet(compareBoth);
433
433
  var isEqual = (u) => hasProperty(u, symbol2);
434
434
  var asEquivalence = () => equals;
435
435
 
436
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/internal/array.js
436
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/internal/array.js
437
437
  var isArrayNonEmpty = (self) => self.length > 0;
438
438
 
439
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Redactable.js
439
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Redactable.js
440
440
  var symbolRedactable = /* @__PURE__ */ Symbol.for("~effect/Inspectable/redactable");
441
441
  var isRedactable = (u) => hasProperty(u, symbolRedactable);
442
442
  function redact(u) {
@@ -455,7 +455,7 @@ var emptyServiceMap = {
455
455
  }
456
456
  };
457
457
 
458
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Formatter.js
458
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Formatter.js
459
459
  function format(input, options) {
460
460
  const space = options?.space ?? 0;
461
461
  const seen = /* @__PURE__ */ new WeakSet();
@@ -534,7 +534,7 @@ function safeToString(input) {
534
534
  }
535
535
  }
536
536
 
537
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Inspectable.js
537
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Inspectable.js
538
538
  var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
539
539
  var toJson = (input) => {
540
540
  try {
@@ -578,7 +578,7 @@ var Class = class {
578
578
  }
579
579
  };
580
580
 
581
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Utils.js
581
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Utils.js
582
582
  var SingleShotGen = class _SingleShotGen {
583
583
  called = false;
584
584
  self;
@@ -621,7 +621,7 @@ var forced = {
621
621
  var isNotOptimizedAway = /* @__PURE__ */ standard[InternalTypeId](() => new Error().stack)?.includes(InternalTypeId) === true;
622
622
  var internalCall = isNotOptimizedAway ? standard[InternalTypeId] : forced[InternalTypeId];
623
623
 
624
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/internal/core.js
624
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/internal/core.js
625
625
  var EffectTypeId = `~effect/Effect`;
626
626
  var ExitTypeId = `~effect/Exit`;
627
627
  var effectVariance = {
@@ -968,7 +968,7 @@ var DoneVoid = {
968
968
  value: void 0
969
969
  };
970
970
 
971
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/internal/option.js
971
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/internal/option.js
972
972
  var TypeId = "~effect/data/Option";
973
973
  var CommonProto = {
974
974
  [TypeId]: {
@@ -1039,7 +1039,7 @@ var some = (value) => {
1039
1039
  return a;
1040
1040
  };
1041
1041
 
1042
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/internal/result.js
1042
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/internal/result.js
1043
1043
  var TypeId2 = "~effect/data/Result";
1044
1044
  var CommonProto2 = {
1045
1045
  [TypeId2]: {
@@ -1110,13 +1110,13 @@ var succeed = (success) => {
1110
1110
  return a;
1111
1111
  };
1112
1112
 
1113
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Order.js
1113
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Order.js
1114
1114
  function make(compare) {
1115
1115
  return (self, that) => self === that ? 0 : compare(self, that);
1116
1116
  }
1117
1117
  var String2 = /* @__PURE__ */ make((self, that) => self < that ? -1 : 1);
1118
1118
 
1119
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Option.js
1119
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Option.js
1120
1120
  var none2 = () => none;
1121
1121
  var some2 = some;
1122
1122
  var isNone2 = isNone;
@@ -1126,7 +1126,7 @@ var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : se
1126
1126
  var fromNullishOr = (a) => a == null ? none2() : some2(a);
1127
1127
  var getOrUndefined = /* @__PURE__ */ getOrElse(constUndefined);
1128
1128
 
1129
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Result.js
1129
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Result.js
1130
1130
  var succeed2 = succeed;
1131
1131
  var fail2 = fail;
1132
1132
  var isFailure2 = isFailure;
@@ -1134,7 +1134,7 @@ var isSuccess2 = isSuccess;
1134
1134
  var map = /* @__PURE__ */ dual(2, (self, f) => isSuccess2(self) ? succeed2(f(self.success)) : fail2(self.failure));
1135
1135
  var getOrElse2 = /* @__PURE__ */ dual(2, (self, onFailure) => isFailure2(self) ? onFailure(self.failure) : self.success);
1136
1136
 
1137
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Record.js
1137
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Record.js
1138
1138
  var map2 = /* @__PURE__ */ dual(2, (self, f) => {
1139
1139
  const out = {
1140
1140
  ...self
@@ -1146,7 +1146,7 @@ var map2 = /* @__PURE__ */ dual(2, (self, f) => {
1146
1146
  });
1147
1147
  var keys = (self) => Object.keys(self);
1148
1148
 
1149
- // ../../node_modules/.pnpm/effect@4.0.0-beta.38/node_modules/effect/dist/Array.js
1149
+ // ../../node_modules/.pnpm/effect@4.0.0-beta.43/node_modules/effect/dist/Array.js
1150
1150
  var Array2 = globalThis.Array;
1151
1151
  var fromIterable = (collection) => Array2.isArray(collection) ? collection : Array2.from(collection);
1152
1152
  var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
@@ -4121,33 +4121,33 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
4121
4121
  ),
4122
4122
  ([Identifier, Service]) => ({ Identifier, Service })
4123
4123
  );
4124
- const serviceVarianceStruct = (type, atLocation) => map4(
4125
- all(
4126
- varianceStructInvariantType(type, atLocation, "_Identifier"),
4127
- varianceStructInvariantType(type, atLocation, "_Service")
4128
- ),
4129
- ([Identifier, Service]) => ({ Identifier, Service })
4130
- );
4131
4124
  const serviceType = cachedBy(
4132
4125
  fn("TypeParser.serviceType")(function* (type, atLocation) {
4126
+ if (supportedEffect() !== "v4") return yield* typeParserIssue("v4 only");
4133
4127
  yield* pipeableType(type, atLocation);
4134
- const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
4135
- (_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration
4136
- );
4137
- if (propertiesSymbols.length === 0) {
4138
- return yield* typeParserIssue("Type has no tag variance struct", type, atLocation);
4128
+ const typeIdSymbol = typeChecker.getPropertyOfType(type, "~effect/ServiceMap/Service");
4129
+ if (!typeIdSymbol) {
4130
+ return yield* typeParserIssue("Type has no service key type id", type, atLocation);
4139
4131
  }
4140
- propertiesSymbols.sort((a, b) => ts.symbolName(b).indexOf("TypeId") - ts.symbolName(a).indexOf("TypeId"));
4141
- return yield* firstSuccessOf(propertiesSymbols.map((propertySymbol) => {
4142
- const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
4143
- return serviceVarianceStruct(propertyType, atLocation);
4144
- }));
4132
+ const identifierSymbol = typeChecker.getPropertyOfType(type, "Identifier");
4133
+ if (!identifierSymbol) {
4134
+ return yield* typeParserIssue("Type has no 'Identifier' property", type, atLocation);
4135
+ }
4136
+ const serviceSymbol = typeChecker.getPropertyOfType(type, "Service");
4137
+ if (!serviceSymbol) {
4138
+ return yield* typeParserIssue("Type has no 'Service' property", type, atLocation);
4139
+ }
4140
+ return {
4141
+ Identifier: typeChecker.getTypeOfSymbolAtLocation(identifierSymbol, atLocation),
4142
+ Service: typeChecker.getTypeOfSymbolAtLocation(serviceSymbol, atLocation)
4143
+ };
4145
4144
  }),
4146
4145
  "TypeParser.serviceType",
4147
4146
  (type) => type
4148
4147
  );
4149
4148
  const contextTag = cachedBy(
4150
4149
  fn("TypeParser.contextTag")(function* (type, atLocation) {
4150
+ if (supportedEffect() !== "v3") return yield* typeParserIssue("v3 only");
4151
4151
  yield* pipeableType(type, atLocation);
4152
4152
  const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
4153
4153
  (_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration
@@ -4288,6 +4288,19 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
4288
4288
  "TypeParser.promiseLike",
4289
4289
  (type) => type
4290
4290
  );
4291
+ const promiseType = cachedBy(
4292
+ function(type, atLocation) {
4293
+ const promiseSymbol = typeChecker.resolveName("Promise", void 0, ts.SymbolFlags.Type, false);
4294
+ if (!promiseSymbol) return typeParserIssue("global Promise type not found", type, atLocation);
4295
+ const globalPromiseType = typeChecker.getDeclaredTypeOfSymbol(promiseSymbol);
4296
+ if (type === globalPromiseType || "target" in type && type.target === globalPromiseType || typeChecker.isTypeAssignableTo(type, globalPromiseType)) {
4297
+ return succeed3(type);
4298
+ }
4299
+ return typeParserIssue("type is not a Promise", type, atLocation);
4300
+ },
4301
+ "TypeParser.promiseType",
4302
+ (type) => type
4303
+ );
4291
4304
  const extendsSchemaClass = cachedBy(
4292
4305
  fn("TypeParser.extendsSchemaClass")(function* (atLocation) {
4293
4306
  if (!atLocation.name) {
@@ -5307,6 +5320,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
5307
5320
  singleArgCall,
5308
5321
  scopeType,
5309
5322
  promiseLike,
5323
+ promiseType,
5310
5324
  extendsEffectTag,
5311
5325
  extendsEffectService,
5312
5326
  extendsServiceMapService,
@@ -5435,6 +5449,37 @@ var anyUnknownInErrorContext = createDiagnostic({
5435
5449
  })
5436
5450
  });
5437
5451
 
5452
+ // src/diagnostics/asyncFunction.ts
5453
+ var asyncFunction = createDiagnostic({
5454
+ name: "asyncFunction",
5455
+ code: 69,
5456
+ description: "Warns when declaring async functions and suggests using Effect values and Effect.gen for async control flow",
5457
+ group: "effectNative",
5458
+ severity: "off",
5459
+ fixable: false,
5460
+ supportedEffect: ["v3", "v4"],
5461
+ apply: fn("asyncFunction.apply")(function* (sourceFile, report) {
5462
+ const ts = yield* service(TypeScriptApi);
5463
+ const hasAsyncModifier = (node) => ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword) === true;
5464
+ const visit = (node) => {
5465
+ if (!ts.isFunctionDeclaration(node) && !ts.isFunctionExpression(node) && !ts.isArrowFunction(node) && !ts.isMethodDeclaration(node)) {
5466
+ ts.forEachChild(node, visit);
5467
+ return void 0;
5468
+ }
5469
+ if (hasAsyncModifier(node)) {
5470
+ report({
5471
+ location: node,
5472
+ messageText: "This code declares an async function, consider representing this async control flow with Effect values and `Effect.gen`.",
5473
+ fixes: []
5474
+ });
5475
+ }
5476
+ ts.forEachChild(node, visit);
5477
+ return void 0;
5478
+ };
5479
+ ts.forEachChild(sourceFile, visit);
5480
+ })
5481
+ });
5482
+
5438
5483
  // src/diagnostics/catchAllToMapError.ts
5439
5484
  var catchAllToMapError = createDiagnostic({
5440
5485
  name: "catchAllToMapError",
@@ -5663,6 +5708,59 @@ var classSelfMismatch = createDiagnostic({
5663
5708
  })
5664
5709
  });
5665
5710
 
5711
+ // src/diagnostics/cryptoRandomUUIDInEffect.ts
5712
+ var makeCryptoRandomUUIDApply = (checkInEffect) => fn(`cryptoRandomUUID${checkInEffect ? "InEffect" : ""}.apply`)(function* (sourceFile, report) {
5713
+ const ts = yield* service(TypeScriptApi);
5714
+ const typeChecker = yield* service(TypeCheckerApi);
5715
+ const typeCheckerUtils = yield* service(TypeCheckerUtils);
5716
+ const typeParser = yield* service(TypeParser);
5717
+ const cryptoSymbol = typeChecker.resolveName("crypto", void 0, ts.SymbolFlags.Value, false);
5718
+ if (!cryptoSymbol) return;
5719
+ const nodeToVisit = [];
5720
+ const appendNodeToVisit = (node) => {
5721
+ nodeToVisit.push(node);
5722
+ return void 0;
5723
+ };
5724
+ ts.forEachChild(sourceFile, appendNodeToVisit);
5725
+ while (nodeToVisit.length > 0) {
5726
+ const node = nodeToVisit.shift();
5727
+ ts.forEachChild(node, appendNodeToVisit);
5728
+ if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression) || ts.idText(node.expression.name) !== "randomUUID") continue;
5729
+ const symbol3 = typeChecker.getSymbolAtLocation(node.expression.expression);
5730
+ if (!symbol3) continue;
5731
+ if (typeCheckerUtils.resolveToGlobalSymbol(symbol3) !== cryptoSymbol) continue;
5732
+ const { inEffect } = yield* typeParser.findEnclosingScopes(node);
5733
+ if (inEffect !== checkInEffect) continue;
5734
+ report({
5735
+ location: node,
5736
+ messageText: checkInEffect ? "This Effect code uses `crypto.randomUUID()`, prefer the Effect `Random` module instead because it uses Effect-injected randomness rather than the `crypto` module behind the scenes." : "This code uses `crypto.randomUUID()`, prefer the Effect `Random` module instead because it uses Effect-injected randomness rather than the `crypto` module behind the scenes.",
5737
+ fixes: []
5738
+ });
5739
+ }
5740
+ });
5741
+ var cryptoRandomUUIDInEffect = createDiagnostic({
5742
+ name: "cryptoRandomUUIDInEffect",
5743
+ code: 67,
5744
+ description: "Warns when using crypto.randomUUID() inside Effect generators instead of the Effect Random module, which uses Effect-injected randomness rather than the crypto module behind the scenes",
5745
+ group: "effectNative",
5746
+ severity: "off",
5747
+ fixable: false,
5748
+ supportedEffect: ["v4"],
5749
+ apply: makeCryptoRandomUUIDApply(true)
5750
+ });
5751
+
5752
+ // src/diagnostics/cryptoRandomUUID.ts
5753
+ var cryptoRandomUUID = createDiagnostic({
5754
+ name: "cryptoRandomUUID",
5755
+ code: 66,
5756
+ description: "Warns when using crypto.randomUUID() outside Effect generators instead of the Effect Random module, which uses Effect-injected randomness rather than the crypto module behind the scenes",
5757
+ group: "effectNative",
5758
+ severity: "off",
5759
+ fixable: false,
5760
+ supportedEffect: ["v4"],
5761
+ apply: makeCryptoRandomUUIDApply(false)
5762
+ });
5763
+
5666
5764
  // src/core/KeyBuilder.ts
5667
5765
  var makeKeyBuilder = fn("KeyBuilder")(
5668
5766
  function* (sourceFile) {
@@ -5880,6 +5978,40 @@ ${versions.map((version) => `- found ${version} at ${resolvedPackages[packageNam
5880
5978
  })
5881
5979
  });
5882
5980
 
5981
+ // src/diagnostics/effectDoNotation.ts
5982
+ var effectDoNotation = createDiagnostic({
5983
+ name: "effectDoNotation",
5984
+ code: 73,
5985
+ description: "Suggests using Effect.gen or Effect.fn instead of the Effect.Do notation helpers",
5986
+ group: "style",
5987
+ severity: "off",
5988
+ fixable: false,
5989
+ supportedEffect: ["v3", "v4"],
5990
+ apply: fn("effectDoNotation.apply")(function* (sourceFile, report) {
5991
+ const ts = yield* service(TypeScriptApi);
5992
+ const typeParser = yield* service(TypeParser);
5993
+ const nodeToVisit = [];
5994
+ const appendNodeToVisit = (node) => {
5995
+ nodeToVisit.push(node);
5996
+ return void 0;
5997
+ };
5998
+ ts.forEachChild(sourceFile, appendNodeToVisit);
5999
+ while (nodeToVisit.length > 0) {
6000
+ const node = nodeToVisit.shift();
6001
+ const isReference = yield* orUndefined(typeParser.isNodeReferenceToEffectModuleApi("Do")(node));
6002
+ if (isReference) {
6003
+ report({
6004
+ location: node,
6005
+ messageText: "This uses the Effect do emulation. `Effect.gen` or `Effect.fn` achieve the same result with native JS scopes.",
6006
+ fixes: []
6007
+ });
6008
+ continue;
6009
+ }
6010
+ ts.forEachChild(node, appendNodeToVisit);
6011
+ }
6012
+ })
6013
+ });
6014
+
5883
6015
  // src/diagnostics/effectFnIife.ts
5884
6016
  var effectFnIife = createDiagnostic({
5885
6017
  name: "effectFnIife",
@@ -6826,6 +6958,43 @@ var effectInVoidSuccess = createDiagnostic({
6826
6958
  })
6827
6959
  });
6828
6960
 
6961
+ // src/diagnostics/effectMapFlatten.ts
6962
+ var effectMapFlatten = createDiagnostic({
6963
+ name: "effectMapFlatten",
6964
+ code: 74,
6965
+ description: "Suggests using Effect.flatMap instead of Effect.map followed by Effect.flatten in piping flows",
6966
+ group: "style",
6967
+ severity: "suggestion",
6968
+ fixable: false,
6969
+ supportedEffect: ["v3", "v4"],
6970
+ apply: fn("effectMapFlatten.apply")(function* (sourceFile, report) {
6971
+ const typeParser = yield* service(TypeParser);
6972
+ const flows = yield* typeParser.pipingFlows(false)(sourceFile);
6973
+ for (const flow2 of flows) {
6974
+ for (let index = 0; index < flow2.transformations.length - 1; index++) {
6975
+ const mapTransformation = flow2.transformations[index];
6976
+ const flattenTransformation = flow2.transformations[index + 1];
6977
+ if (!mapTransformation || !flattenTransformation || !mapTransformation?.args || flattenTransformation?.args || mapTransformation.kind !== "pipe" && mapTransformation.kind !== "pipeable" || flattenTransformation.kind !== mapTransformation.kind) {
6978
+ continue;
6979
+ }
6980
+ const isMapCall = yield* orUndefined(
6981
+ typeParser.isNodeReferenceToEffectModuleApi("map")(mapTransformation.callee)
6982
+ );
6983
+ const isFlattenCall = yield* orUndefined(
6984
+ typeParser.isNodeReferenceToEffectModuleApi("flatten")(flattenTransformation.callee)
6985
+ );
6986
+ if (isMapCall && isFlattenCall) {
6987
+ report({
6988
+ location: flattenTransformation.callee,
6989
+ messageText: "`Effect.map` + `Effect.flatten` is the same as `Effect.flatMap` that expresses the same steps more directly.",
6990
+ fixes: []
6991
+ });
6992
+ }
6993
+ }
6994
+ }
6995
+ })
6996
+ });
6997
+
6829
6998
  // src/diagnostics/effectMapVoid.ts
6830
6999
  var effectMapVoid = createDiagnostic({
6831
7000
  name: "effectMapVoid",
@@ -7093,6 +7262,7 @@ var genericEffectServices = createDiagnostic({
7093
7262
  for (const [type, reportAt] of typesToCheck) {
7094
7263
  yield* pipe(
7095
7264
  typeParser.contextTag(type, node),
7265
+ orElse2(() => typeParser.serviceType(type, node)),
7096
7266
  map4(() => {
7097
7267
  report({
7098
7268
  location: reportAt,
@@ -7856,6 +8026,55 @@ var layerMergeAllWithDependencies = createDiagnostic({
7856
8026
  })
7857
8027
  });
7858
8028
 
8029
+ // src/diagnostics/lazyPromiseInEffectSync.ts
8030
+ var lazyPromiseInEffectSync = createDiagnostic({
8031
+ name: "lazyPromiseInEffectSync",
8032
+ code: 70,
8033
+ description: "Warns when Effect.sync lazily returns a Promise instead of using an async Effect constructor",
8034
+ group: "antipattern",
8035
+ severity: "warning",
8036
+ fixable: false,
8037
+ supportedEffect: ["v3", "v4"],
8038
+ apply: fn("lazyPromiseInEffectSync.apply")(function* (sourceFile, report) {
8039
+ const ts = yield* service(TypeScriptApi);
8040
+ const typeChecker = yield* service(TypeCheckerApi);
8041
+ const typeCheckerUtils = yield* service(TypeCheckerUtils);
8042
+ const typeParser = yield* service(TypeParser);
8043
+ const nodeToVisit = [];
8044
+ const appendNodeToVisit = (node) => {
8045
+ nodeToVisit.push(node);
8046
+ return void 0;
8047
+ };
8048
+ ts.forEachChild(sourceFile, appendNodeToVisit);
8049
+ while (nodeToVisit.length > 0) {
8050
+ const node = nodeToVisit.shift();
8051
+ ts.forEachChild(node, appendNodeToVisit);
8052
+ if (!ts.isCallExpression(node)) continue;
8053
+ const isSyncCall = yield* orUndefined(
8054
+ typeParser.isNodeReferenceToEffectModuleApi("sync")(node.expression)
8055
+ );
8056
+ if (!isSyncCall) continue;
8057
+ const lazyArg = node.arguments[0];
8058
+ if (!lazyArg) continue;
8059
+ const lazyArgType = typeCheckerUtils.getTypeAtLocation(lazyArg);
8060
+ if (!lazyArgType) continue;
8061
+ const entries = typeCheckerUtils.unrollUnionMembers(lazyArgType).flatMap(
8062
+ (member) => typeChecker.getSignaturesOfType(member, ts.SignatureKind.Call).map(
8063
+ (signature) => typeParser.promiseType(typeChecker.getReturnTypeOfSignature(signature), lazyArg)
8064
+ )
8065
+ );
8066
+ if (entries.length === 0) continue;
8067
+ const promiseReturn = yield* orUndefined(firstSuccessOf(entries));
8068
+ if (!promiseReturn) continue;
8069
+ report({
8070
+ location: lazyArg,
8071
+ messageText: "This `Effect.sync` thunk returns a Promise. Use `Effect.promise` or `Effect.tryPromise` to represent async work.",
8072
+ fixes: []
8073
+ });
8074
+ }
8075
+ })
8076
+ });
8077
+
7859
8078
  // src/diagnostics/leakingRequirements.ts
7860
8079
  var leakingRequirements = createDiagnostic({
7861
8080
  name: "leakingRequirements",
@@ -8789,6 +9008,74 @@ var multipleEffectProvide = createDiagnostic({
8789
9008
  })
8790
9009
  });
8791
9010
 
9011
+ // src/diagnostics/nestedEffectGenYield.ts
9012
+ var nestedEffectGenYield = createDiagnostic({
9013
+ name: "nestedEffectGenYield",
9014
+ code: 71,
9015
+ description: "Warns when yielding a nested bare Effect.gen inside an existing Effect generator context",
9016
+ group: "style",
9017
+ severity: "off",
9018
+ fixable: false,
9019
+ supportedEffect: ["v3", "v4"],
9020
+ apply: fn("nestedEffectGenYield.apply")(function* (sourceFile, report) {
9021
+ const ts = yield* service(TypeScriptApi);
9022
+ const typeParser = yield* service(TypeParser);
9023
+ const nodeToVisit = [];
9024
+ const appendNodeToVisit = (node) => {
9025
+ nodeToVisit.push(node);
9026
+ return void 0;
9027
+ };
9028
+ ts.forEachChild(sourceFile, appendNodeToVisit);
9029
+ while (nodeToVisit.length > 0) {
9030
+ const node = nodeToVisit.shift();
9031
+ ts.forEachChild(node, appendNodeToVisit);
9032
+ if (!ts.isYieldExpression(node) || !node.asteriskToken || !node.expression) continue;
9033
+ const { inEffect } = yield* typeParser.findEnclosingScopes(node);
9034
+ if (!inEffect) continue;
9035
+ const bareNestedEffectGen = yield* orUndefined(typeParser.effectGen(node.expression));
9036
+ if (!bareNestedEffectGen) continue;
9037
+ report({
9038
+ location: node.expression,
9039
+ messageText: "This `yield*` is applied to a nested `Effect.gen(...)` that can be inlined in the parent Effect generator context.",
9040
+ fixes: []
9041
+ });
9042
+ }
9043
+ })
9044
+ });
9045
+
9046
+ // src/diagnostics/newPromise.ts
9047
+ var newPromise = createDiagnostic({
9048
+ name: "newPromise",
9049
+ code: 68,
9050
+ description: "Warns when constructing promises with new Promise instead of using Effect APIs",
9051
+ group: "effectNative",
9052
+ severity: "off",
9053
+ fixable: false,
9054
+ supportedEffect: ["v3", "v4"],
9055
+ apply: fn("newPromise.apply")(function* (sourceFile, report) {
9056
+ const ts = yield* service(TypeScriptApi);
9057
+ const typeChecker = yield* service(TypeCheckerApi);
9058
+ const typeCheckerUtils = yield* service(TypeCheckerUtils);
9059
+ const promiseSymbol = typeChecker.resolveName("Promise", void 0, ts.SymbolFlags.Value, false);
9060
+ if (!promiseSymbol) return;
9061
+ const visit = (node) => {
9062
+ if (ts.isNewExpression(node)) {
9063
+ const symbol3 = typeChecker.getSymbolAtLocation(node.expression);
9064
+ if (symbol3 && typeCheckerUtils.resolveToGlobalSymbol(symbol3) === promiseSymbol) {
9065
+ report({
9066
+ location: node,
9067
+ messageText: "This code constructs `new Promise(...)`, prefer Effect APIs such as `Effect.async`, `Effect.promise`, or `Effect.tryPromise` instead of manual Promise construction.",
9068
+ fixes: []
9069
+ });
9070
+ }
9071
+ }
9072
+ ts.forEachChild(node, visit);
9073
+ return void 0;
9074
+ };
9075
+ ts.forEachChild(sourceFile, visit);
9076
+ })
9077
+ });
9078
+
8792
9079
  // src/diagnostics/nodeBuiltinImport.ts
8793
9080
  var moduleAlternativesV3 = /* @__PURE__ */ new Map([
8794
9081
  ["fs", { alternative: "FileSystem", module: "fs", package: "@effect/platform" }],
@@ -9132,6 +9419,14 @@ var effectModuleMigrationDb = {
9132
9419
  "yieldNow": asUnchanged,
9133
9420
  "zip": asUnchanged,
9134
9421
  "zipWith": asUnchanged,
9422
+ "annotateLogsScoped": asUnchanged,
9423
+ "awaitAllChildren": asUnchanged,
9424
+ "bind": asUnchanged,
9425
+ "bindTo": asUnchanged,
9426
+ "Do": asUnchanged,
9427
+ "let": asUnchanged,
9428
+ "partition": asUnchanged,
9429
+ "validate": asUnchanged,
9135
9430
  // Renamed APIs (v3 name → v4 name)
9136
9431
  "catchAll": asRenamedSameBehaviour("catch"),
9137
9432
  "catchAllCause": asRenamedSameBehaviour("catchCause"),
@@ -9151,14 +9446,6 @@ var effectModuleMigrationDb = {
9151
9446
  "serviceOptional": asRenamedSameBehaviour("serviceOption"),
9152
9447
  "tapErrorCause": asRenamedSameBehaviour("tapCause"),
9153
9448
  // Removed APIs
9154
- "annotateLogsScoped": asUnchanged,
9155
- "awaitAllChildren": asUnchanged,
9156
- "bind": asUnchanged,
9157
- "bindTo": asUnchanged,
9158
- "Do": asUnchanged,
9159
- "let": asUnchanged,
9160
- "partition": asUnchanged,
9161
- "validate": asUnchanged,
9162
9449
  "catchSomeDefect": asRemoved(
9163
9450
  "Use Effect.catchDefect or Effect.matchCause to handle specific defects."
9164
9451
  ),
@@ -11092,6 +11379,63 @@ var preferSchemaOverJson = createDiagnostic({
11092
11379
  })
11093
11380
  });
11094
11381
 
11382
+ // src/diagnostics/processEnvInEffect.ts
11383
+ var isEnvPropertyAccess = (tsApi, node) => tsApi.isPropertyAccessExpression(node) && tsApi.idText(node.name) === "env";
11384
+ var isProcessEnvMemberAccess = (tsApi, node) => (tsApi.isPropertyAccessExpression(node) || tsApi.isElementAccessExpression(node)) && isEnvPropertyAccess(tsApi, node.expression);
11385
+ var makeProcessEnvApply = (checkInEffect) => fn(`processEnv${checkInEffect ? "InEffect" : ""}.apply`)(function* (sourceFile, report) {
11386
+ const ts = yield* service(TypeScriptApi);
11387
+ const typeChecker = yield* service(TypeCheckerApi);
11388
+ const typeCheckerUtils = yield* service(TypeCheckerUtils);
11389
+ const typeParser = yield* service(TypeParser);
11390
+ const processSymbol = typeChecker.resolveName("process", void 0, ts.SymbolFlags.Value, false);
11391
+ if (!processSymbol) return;
11392
+ const nodeToVisit = [];
11393
+ const appendNodeToVisit = (node) => {
11394
+ nodeToVisit.push(node);
11395
+ return void 0;
11396
+ };
11397
+ ts.forEachChild(sourceFile, appendNodeToVisit);
11398
+ while (nodeToVisit.length > 0) {
11399
+ const node = nodeToVisit.shift();
11400
+ ts.forEachChild(node, appendNodeToVisit);
11401
+ if (!isProcessEnvMemberAccess(ts, node)) continue;
11402
+ const processNode = node.expression.expression;
11403
+ if (!ts.isIdentifier(processNode) || ts.idText(processNode) !== "process") continue;
11404
+ const symbol3 = typeChecker.getSymbolAtLocation(processNode);
11405
+ if (!symbol3) continue;
11406
+ if (typeCheckerUtils.resolveToGlobalSymbol(symbol3) !== processSymbol) continue;
11407
+ const { inEffect } = yield* typeParser.findEnclosingScopes(node);
11408
+ if (inEffect !== checkInEffect) continue;
11409
+ report({
11410
+ location: node,
11411
+ messageText: checkInEffect ? "This Effect code reads from `process.env`, environment configuration in Effect code is represented through `Config` from Effect." : "This code reads from `process.env`, environment configuration is represented through `Config` from Effect.",
11412
+ fixes: []
11413
+ });
11414
+ }
11415
+ });
11416
+ var processEnvInEffect = createDiagnostic({
11417
+ name: "processEnvInEffect",
11418
+ code: 65,
11419
+ description: "Warns when reading process.env inside Effect generators instead of using Effect Config",
11420
+ group: "effectNative",
11421
+ severity: "off",
11422
+ fixable: false,
11423
+ supportedEffect: ["v3", "v4"],
11424
+ apply: makeProcessEnvApply(true)
11425
+ });
11426
+
11427
+ // src/diagnostics/processEnv.ts
11428
+ var processEnv = createDiagnostic({
11429
+ name: "processEnv",
11430
+ code: 64,
11431
+ description: "Warns when reading process.env outside Effect generators instead of using Effect Config",
11432
+ group: "effectNative",
11433
+ severity: "off",
11434
+ fixable: false,
11435
+ supportedEffect: ["v3", "v4"],
11436
+ apply: makeProcessEnvApply(false)
11437
+ });
11438
+
11095
11439
  // src/diagnostics/redundantSchemaTagIdentifier.ts
11096
11440
  var redundantSchemaTagIdentifier = createDiagnostic({
11097
11441
  name: "redundantSchemaTagIdentifier",
@@ -12029,6 +12373,56 @@ var unknownInEffectCatch = createDiagnostic({
12029
12373
  })
12030
12374
  });
12031
12375
 
12376
+ // src/diagnostics/unnecessaryArrowBlock.ts
12377
+ var unnecessaryArrowBlock = createDiagnostic({
12378
+ name: "unnecessaryArrowBlock",
12379
+ code: 72,
12380
+ description: "Suggests using a concise arrow body when the block only returns an expression",
12381
+ group: "style",
12382
+ severity: "off",
12383
+ fixable: true,
12384
+ supportedEffect: ["v3", "v4"],
12385
+ apply: fn("unnecessaryArrowBlock.apply")(function* (sourceFile, report) {
12386
+ const ts = yield* service(TypeScriptApi);
12387
+ const nodeToVisit = [];
12388
+ const appendNodeToVisit = (node) => {
12389
+ nodeToVisit.push(node);
12390
+ return void 0;
12391
+ };
12392
+ ts.forEachChild(sourceFile, appendNodeToVisit);
12393
+ while (nodeToVisit.length > 0) {
12394
+ const node = nodeToVisit.shift();
12395
+ ts.forEachChild(node, appendNodeToVisit);
12396
+ if (!ts.isArrowFunction(node) || !ts.isBlock(node.body)) continue;
12397
+ if (node.body.statements.length !== 1) continue;
12398
+ const [statement] = node.body.statements;
12399
+ if (!ts.isReturnStatement(statement) || !statement.expression) continue;
12400
+ const returnedExpression = statement.expression;
12401
+ report({
12402
+ location: node.body,
12403
+ messageText: "This arrow function block only returns an expression and can use a concise body.",
12404
+ fixes: [{
12405
+ fixName: "unnecessaryArrowBlock_fix",
12406
+ description: "Use a concise arrow body",
12407
+ apply: gen(function* () {
12408
+ const changeTracker = yield* service(ChangeTracker);
12409
+ const replacementNode = ts.factory.updateArrowFunction(
12410
+ node,
12411
+ node.modifiers,
12412
+ node.typeParameters,
12413
+ node.parameters,
12414
+ node.type,
12415
+ node.equalsGreaterThanToken,
12416
+ ts.factory.createParenthesizedExpression(returnedExpression)
12417
+ );
12418
+ changeTracker.replaceNode(sourceFile, node, replacementNode);
12419
+ })
12420
+ }]
12421
+ });
12422
+ }
12423
+ })
12424
+ });
12425
+
12032
12426
  // src/diagnostics/unnecessaryEffectGen.ts
12033
12427
  var unnecessaryEffectGen = createDiagnostic({
12034
12428
  name: "unnecessaryEffectGen",
@@ -12329,12 +12723,17 @@ var unsupportedServiceAccessors = createDiagnostic({
12329
12723
  var diagnostics = [
12330
12724
  outdatedApi,
12331
12725
  anyUnknownInErrorContext,
12726
+ asyncFunction,
12332
12727
  instanceOfSchema,
12333
12728
  catchAllToMapError,
12334
12729
  catchUnfailableEffect,
12335
12730
  classSelfMismatch,
12731
+ cryptoRandomUUID,
12732
+ cryptoRandomUUIDInEffect,
12336
12733
  duplicatePackage,
12734
+ effectDoNotation,
12337
12735
  effectFnImplicitAny,
12736
+ effectMapFlatten,
12338
12737
  effectGenUsesAdapter,
12339
12738
  missingEffectContext,
12340
12739
  missingEffectError,
@@ -12343,6 +12742,8 @@ var diagnostics = [
12343
12742
  floatingEffect,
12344
12743
  effectInFailure,
12345
12744
  missingStarInYieldEffectGen,
12745
+ newPromise,
12746
+ lazyPromiseInEffectSync,
12346
12747
  unnecessaryEffectGen,
12347
12748
  unnecessaryFailYieldableError,
12348
12749
  missingReturnYieldStar,
@@ -12351,6 +12752,8 @@ var diagnostics = [
12351
12752
  genericEffectServices,
12352
12753
  globalFetch,
12353
12754
  globalFetchInEffect,
12755
+ processEnv,
12756
+ processEnvInEffect,
12354
12757
  returnEffectInGen,
12355
12758
  tryCatchInEffectGen,
12356
12759
  importFromBarrel,
@@ -12368,6 +12771,8 @@ var diagnostics = [
12368
12771
  strictEffectProvide,
12369
12772
  unknownInEffectCatch,
12370
12773
  runEffectInsideEffect,
12774
+ nestedEffectGenYield,
12775
+ unnecessaryArrowBlock,
12371
12776
  schemaUnionOfLiterals,
12372
12777
  schemaStructWithTag,
12373
12778
  globalErrorInEffectCatch,