Skip to content

Commit 5f76175

Browse files
Extend node builtin import diagnostic to http modules (#686)
1 parent d94f4ad commit 5f76175

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
lines changed

.changeset/famous-garlics-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@effect/language-service": patch
3+
---
4+
5+
Extend the node built-in import diagnostic to also recommend the Effect HTTP client for `http` and `https` imports.

packages/harness-effect-v4/__snapshots__/diagnostics/nodeBuiltinImport.ts.codefixes

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ nodeBuiltinImport_skipNextLine from 398 to 413
1616
nodeBuiltinImport_skipFile from 398 to 413
1717
nodeBuiltinImport_skipNextLine from 436 to 456
1818
nodeBuiltinImport_skipFile from 436 to 456
19-
nodeBuiltinImport_skipNextLine from 496 to 505
20-
nodeBuiltinImport_skipFile from 496 to 505
21-
nodeBuiltinImport_skipNextLine from 557 to 566
22-
nodeBuiltinImport_skipFile from 557 to 566
19+
nodeBuiltinImport_skipNextLine from 474 to 480
20+
nodeBuiltinImport_skipFile from 474 to 480
21+
nodeBuiltinImport_skipNextLine from 499 to 511
22+
nodeBuiltinImport_skipFile from 499 to 511
23+
nodeBuiltinImport_skipNextLine from 551 to 560
24+
nodeBuiltinImport_skipFile from 551 to 560
25+
nodeBuiltinImport_skipNextLine from 612 to 621
26+
nodeBuiltinImport_skipFile from 612 to 621

packages/harness-effect-v4/__snapshots__/diagnostics/nodeBuiltinImport.ts.output

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@
2525
"node:child_process"
2626
13:22 - 13:42 | 0 | Prefer using ChildProcess from effect instead of the Node.js 'child_process' module. effect(nodeBuiltinImport)
2727

28+
"http"
29+
14:17 - 14:23 | 0 | Prefer using HttpClient from effect/unstable/http instead of the Node.js 'http' module. effect(nodeBuiltinImport)
30+
31+
"node:https"
32+
15:18 - 15:30 | 0 | Prefer using HttpClient from effect/unstable/http instead of the Node.js 'https' module. effect(nodeBuiltinImport)
33+
2834
"node:fs"
29-
16:7 - 16:16 | 0 | Prefer using FileSystem from effect instead of the Node.js 'fs' module. effect(nodeBuiltinImport)
35+
18:7 - 18:16 | 0 | Prefer using FileSystem from effect instead of the Node.js 'fs' module. effect(nodeBuiltinImport)
3036

3137
"node:fs"
32-
19:20 - 19:29 | 0 | Prefer using FileSystem from effect instead of the Node.js 'fs' module. effect(nodeBuiltinImport)
38+
21:20 - 21:29 | 0 | Prefer using FileSystem from effect instead of the Node.js 'fs' module. effect(nodeBuiltinImport)

packages/harness-effect-v4/examples/diagnostics/nodeBuiltinImport.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import path from "node:path"
1111
import { join as join2 } from "path/posix"
1212
import { exec } from "child_process"
1313
import { spawn } from "node:child_process"
14+
import http from "http"
15+
import https from "node:https"
1416

1517
// Flagged: side-effect import
1618
import "node:fs"
@@ -22,9 +24,6 @@ const fs3 = require("node:fs")
2224
// @ts-expect-error - @effect/platform not installed in harness
2325
import { FileSystem } from "@effect/platform"
2426

25-
// Not flagged: unrelated Node built-ins
26-
import http from "http"
27-
2827
// Not flagged: third-party modules with similar names
2928
// @ts-expect-error - fs-extra not installed in harness
3029
import fsExtra from "fs-extra"

packages/language-service/src/diagnostics/nodeBuiltinImport.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ const moduleAlternativesV3 = new Map<string, { alternative: string; module: stri
1515
["path/win32", { alternative: "Path", module: "path", package: "@effect/platform" }],
1616
["node:path/win32", { alternative: "Path", module: "path", package: "@effect/platform" }],
1717
["child_process", { alternative: "CommandExecutor", module: "child_process", package: "@effect/platform" }],
18-
["node:child_process", { alternative: "CommandExecutor", module: "child_process", package: "@effect/platform" }]
18+
["node:child_process", { alternative: "CommandExecutor", module: "child_process", package: "@effect/platform" }],
19+
["http", { alternative: "HttpClient", module: "http", package: "@effect/platform" }],
20+
["node:http", { alternative: "HttpClient", module: "http", package: "@effect/platform" }],
21+
["https", { alternative: "HttpClient", module: "https", package: "@effect/platform" }],
22+
["node:https", { alternative: "HttpClient", module: "https", package: "@effect/platform" }]
1923
])
2024

2125
const moduleAlternativesV4 = new Map<string, { alternative: string; module: string; package: string }>([
@@ -30,7 +34,11 @@ const moduleAlternativesV4 = new Map<string, { alternative: string; module: stri
3034
["path/win32", { alternative: "Path", module: "path", package: "effect" }],
3135
["node:path/win32", { alternative: "Path", module: "path", package: "effect" }],
3236
["child_process", { alternative: "ChildProcess", module: "child_process", package: "effect" }],
33-
["node:child_process", { alternative: "ChildProcess", module: "child_process", package: "effect" }]
37+
["node:child_process", { alternative: "ChildProcess", module: "child_process", package: "effect" }],
38+
["http", { alternative: "HttpClient", module: "http", package: "effect/unstable/http" }],
39+
["node:http", { alternative: "HttpClient", module: "http", package: "effect/unstable/http" }],
40+
["https", { alternative: "HttpClient", module: "https", package: "effect/unstable/http" }],
41+
["node:https", { alternative: "HttpClient", module: "https", package: "effect/unstable/http" }]
3442
])
3543

3644
export const nodeBuiltinImport = LSP.createDiagnostic({

0 commit comments

Comments
 (0)