@effect/language-service 0.25.1 → 0.26.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/language-service",
3
- "version": "0.25.1",
3
+ "version": "0.26.0",
4
4
  "description": "A Language-Service Plugin to Refactor and Diagnostic effect-ts projects",
5
5
  "main": "index.cjs",
6
6
  "bin": {
package/transform.js CHANGED
@@ -2499,11 +2499,16 @@ function make2(ts, typeChecker) {
2499
2499
  const pipeCall = cachedBy(
2500
2500
  function(node) {
2501
2501
  if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && node.expression.name.text === "pipe") {
2502
- return succeed({ node, subject: node.expression.expression, args: Array.from(node.arguments) });
2502
+ return succeed({
2503
+ node,
2504
+ subject: node.expression.expression,
2505
+ args: Array.from(node.arguments),
2506
+ kind: "pipeable"
2507
+ });
2503
2508
  }
2504
2509
  if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "pipe" && node.arguments.length > 0) {
2505
2510
  const [subject, ...args2] = node.arguments;
2506
- return succeed({ node, subject, args: args2 });
2511
+ return succeed({ node, subject, args: args2, kind: "pipe" });
2507
2512
  }
2508
2513
  return typeParserIssue("Node is not a pipe call", void 0, node);
2509
2514
  },
@@ -2542,6 +2547,7 @@ function make2(ts, typeChecker) {
2542
2547
  unnecessaryEffectGen: unnecessaryEffectGen2,
2543
2548
  effectSchemaType,
2544
2549
  contextTag,
2550
+ pipeableType,
2545
2551
  pipeCall,
2546
2552
  scopeType
2547
2553
  };
@@ -3478,7 +3484,7 @@ Consider using "scoped" instead to get rid of the scope in the requirements.`,
3478
3484
  // src/diagnostics/tryCatchInEffectGen.ts
3479
3485
  var tryCatchInEffectGen = createDiagnostic({
3480
3486
  name: "tryCatchInEffectGen",
3481
- code: 12,
3487
+ code: 15,
3482
3488
  severity: "suggestion",
3483
3489
  apply: fn("tryCatchInEffectGen.apply")(function* (sourceFile, report) {
3484
3490
  const ts = yield* service(TypeScriptApi);
@@ -3608,6 +3614,80 @@ var unnecessaryPipe = createDiagnostic({
3608
3614
  })
3609
3615
  });
3610
3616
 
3617
+ // src/diagnostics/unnecessaryPipeChain.ts
3618
+ var unnecessaryPipeChain = createDiagnostic({
3619
+ name: "unnecessaryPipeChain",
3620
+ code: 16,
3621
+ severity: "suggestion",
3622
+ apply: fn("unnecessaryPipeChain.apply")(function* (sourceFile, report) {
3623
+ const ts = yield* service(TypeScriptApi);
3624
+ const typeParser = yield* service(TypeParser);
3625
+ const nodeToVisit = [];
3626
+ const appendNodeToVisit = (node) => {
3627
+ nodeToVisit.push(node);
3628
+ return void 0;
3629
+ };
3630
+ ts.forEachChild(sourceFile, appendNodeToVisit);
3631
+ while (nodeToVisit.length > 0) {
3632
+ const node = nodeToVisit.shift();
3633
+ ts.forEachChild(node, appendNodeToVisit);
3634
+ if (ts.isCallExpression(node)) {
3635
+ yield* pipe(
3636
+ typeParser.pipeCall(node),
3637
+ flatMap2(
3638
+ (pipeCall) => map3(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))
3639
+ ),
3640
+ map3(({ innerCall, pipeCall }) => {
3641
+ report({
3642
+ node,
3643
+ messageText: `Chained pipe calls can be simplified to a single pipe call`,
3644
+ fixes: [{
3645
+ fixName: "unnecessaryPipeChain_fix",
3646
+ description: "Rewrite as single pipe call",
3647
+ apply: gen(function* () {
3648
+ const changeTracker = yield* service(
3649
+ ChangeTracker
3650
+ );
3651
+ switch (innerCall.kind) {
3652
+ case "pipe": {
3653
+ changeTracker.replaceNode(
3654
+ sourceFile,
3655
+ node,
3656
+ ts.factory.createCallExpression(
3657
+ ts.factory.createIdentifier("pipe"),
3658
+ void 0,
3659
+ [innerCall.subject, ...innerCall.args, ...pipeCall.args]
3660
+ )
3661
+ );
3662
+ break;
3663
+ }
3664
+ case "pipeable": {
3665
+ changeTracker.replaceNode(
3666
+ sourceFile,
3667
+ node,
3668
+ ts.factory.createCallExpression(
3669
+ ts.factory.createPropertyAccessExpression(
3670
+ innerCall.subject,
3671
+ "pipe"
3672
+ ),
3673
+ void 0,
3674
+ [...innerCall.args, ...pipeCall.args]
3675
+ )
3676
+ );
3677
+ break;
3678
+ }
3679
+ }
3680
+ })
3681
+ }]
3682
+ });
3683
+ }),
3684
+ ignore
3685
+ );
3686
+ }
3687
+ }
3688
+ })
3689
+ });
3690
+
3611
3691
  // src/diagnostics.ts
3612
3692
  var diagnostics = [
3613
3693
  duplicatePackage,
@@ -3624,7 +3704,8 @@ var diagnostics = [
3624
3704
  tryCatchInEffectGen,
3625
3705
  importFromBarrel,
3626
3706
  scopeInLayerEffect,
3627
- effectInVoidSuccess
3707
+ effectInVoidSuccess,
3708
+ unnecessaryPipeChain
3628
3709
  ];
3629
3710
 
3630
3711
  // src/transform.ts