Skip to content

Latest commit

 

History

History
66 lines (54 loc) · 1.52 KB

global-random-in-effect.md

File metadata and controls

66 lines (54 loc) · 1.52 KB

globalRandomInEffect

Warns when using Math.random() inside Effect generators instead of the Random service

Property Value
Category Effect-native
Default severity off
Fixable No
Effect versions v3, v4
Diagnostic codes TS377071
Language Service name globalRandomInEffect
Oxlint name effecttsgo/global-random-in-effect

Preview

import { Effect } from "effect"

export const preview = Effect.gen(function*() {
  const r = Math.random()
/**
            ^^^^^^^^^^^^^ effecttsgo(global-random-in-effect): This Effect code uses `Math.random()`, randomness is represented through the Effect `Random` service.
*/
  return r
})

Language Service Configuration

See the Language Service setup guide for installation instructions.

{
  "$schema": "./node_modules/@effect/tsgo/schema.json",
  "compilerOptions": {
    "plugins": [
      {
        "name": "@effect/language-service",
        "diagnosticSeverity": {
          "globalRandomInEffect": "warning"
        }
      }
    ]
  }
}

Oxlint Configuration

See the Oxlint setup guide for installation and patching instructions.

{
  "$schema": "./node_modules/@effect/tsgo/oxlint-schema.json",
  "options": {
    "typeAware": true
  },
  "plugins": ["effecttsgo"],
  "rules": {
    "effecttsgo/global-random-in-effect": "warn"
  }
}