Skip to content

Commit 78e78d5

Browse files
authored
Add globalDate, globalConsole, globalRandom, globalTimers diagnostics (#696)
1 parent 799f63a commit 78e78d5

File tree

58 files changed

+998
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+998
-4
lines changed

.changeset/global-diagnostics.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@effect/language-service": minor
3+
---
4+
5+
Add globalDate, globalConsole, globalRandom, and globalTimers diagnostics
6+
7+
Four new opt-in diagnostics that flag global/DOM APIs inside Effect generators:
8+
9+
- `globalDate``Date.now()`, `new Date()` → Clock/DateTime
10+
- `globalConsole``console.log/warn/error/info/debug/trace` → Effect.log/Logger
11+
- `globalRandom``Math.random()` → Random service
12+
- `globalTimers``setTimeout/setInterval` → Effect.sleep/Schedule
13+
14+
All default to `off`. Shadow-safe (e.g. `const console = yield* Console` won't false-positive).

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ Some diagnostics are off by default or have a default severity of suggestion, bu
8989
<tr><td><code>unknownInEffectCatch</code></td><td>⚠️</td><td></td><td>Warns when catch callbacks return unknown instead of typed errors</td><td>✓</td><td>✓</td></tr>
9090
<tr><td colspan="6"><strong>Effect-native</strong> <em>Prefer Effect-native APIs and abstractions when available.</em></td></tr>
9191
<tr><td><code>extendsNativeError</code></td><td>➖</td><td></td><td>Warns when a class directly extends the native Error class</td><td>✓</td><td>✓</td></tr>
92+
<tr><td><code>globalConsole</code></td><td>➖</td><td></td><td>Warns when using console methods inside Effect generators instead of Effect.log/Logger</td><td>✓</td><td>✓</td></tr>
93+
<tr><td><code>globalDate</code></td><td>➖</td><td></td><td>Warns when using Date.now() or new Date() inside Effect generators instead of Clock/DateTime</td><td>✓</td><td>✓</td></tr>
9294
<tr><td><code>globalFetch</code></td><td>➖</td><td></td><td>Warns when using the global fetch function instead of the Effect HTTP client</td><td>✓</td><td>✓</td></tr>
95+
<tr><td><code>globalRandom</code></td><td>➖</td><td></td><td>Warns when using Math.random() inside Effect generators instead of the Random service</td><td>✓</td><td>✓</td></tr>
96+
<tr><td><code>globalTimers</code></td><td>➖</td><td></td><td>Warns when using setTimeout/setInterval inside Effect generators instead of Effect.sleep/Schedule</td><td>✓</td><td>✓</td></tr>
9397
<tr><td><code>instanceOfSchema</code></td><td>➖</td><td>🔧</td><td>Suggests using Schema.is instead of instanceof for Effect Schema types</td><td>✓</td><td>✓</td></tr>
9498
<tr><td><code>nodeBuiltinImport</code></td><td>➖</td><td></td><td>Warns when importing Node.js built-in modules that have Effect-native counterparts</td><td>✓</td><td>✓</td></tr>
9599
<tr><td><code>preferSchemaOverJson</code></td><td>💡</td><td></td><td>Suggests using Effect Schema for JSON operations instead of JSON.parse/JSON.stringify which may throw</td><td>✓</td><td>✓</td></tr>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
globalConsole_skipNextLine from 195 to 215
2+
globalConsole_skipFile from 195 to 215
3+
globalConsole_skipNextLine from 346 to 369
4+
globalConsole_skipFile from 346 to 369
5+
globalConsole_skipNextLine from 486 to 508
6+
globalConsole_skipFile from 486 to 508
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
console.log("hello")
2+
6:2 - 6:22 | 0 | Prefer using Effect.log or Logger instead of console.log inside Effect generators. effect(globalConsole)
3+
4+
console.warn("warning")
5+
11:2 - 11:25 | 0 | Prefer using Effect.logWarning or Logger instead of console.warn inside Effect generators. effect(globalConsole)
6+
7+
console.error("error")
8+
16:2 - 16:24 | 0 | Prefer using Effect.logError or Logger instead of console.error inside Effect generators. effect(globalConsole)
9+
10+
myConsole.log("hello")
11+
22:2 - 22:24 | 0 | Prefer using Effect.log or Logger instead of console.log inside Effect generators. effect(globalConsole)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
globalConsole_skipNextLine from 157 to 177
2+
globalConsole_skipFile from 157 to 177
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log("hello")
2+
6:2 - 6:22 | 0 | Prefer using Effect.log or Logger instead of console.log inside Effect generators. effect(globalConsole)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
globalDate_skipNextLine from 191 to 201
2+
globalDate_skipFile from 191 to 201
3+
globalDate_skipNextLine from 335 to 345
4+
globalDate_skipFile from 335 to 345
5+
globalDate_skipNextLine from 521 to 543
6+
globalDate_skipFile from 521 to 543
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Date.now()
2+
6:14 - 6:24 | 0 | Prefer using Clock or DateTime from Effect instead of Date.now() inside Effect generators. effect(globalDate)
3+
4+
new Date()
5+
12:14 - 12:24 | 0 | Prefer using DateTime from Effect instead of new Date() inside Effect generators. effect(globalDate)
6+
7+
new Date("2024-01-01")
8+
18:15 - 18:37 | 0 | Prefer using DateTime from Effect instead of new Date() inside Effect generators. effect(globalDate)
9+
10+
MyDate.now()
11+
25:14 - 25:26 | 0 | Prefer using Clock or DateTime from Effect instead of Date.now() inside Effect generators. effect(globalDate)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
globalDate_skipNextLine from 166 to 176
2+
globalDate_skipFile from 166 to 176
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Date.now()
2+
6:14 - 6:24 | 0 | Prefer using Clock or DateTime from Effect instead of Date.now() inside Effect generators. effect(globalDate)

0 commit comments

Comments
 (0)