Skip to content

Latest commit

 

History

History
66 lines (54 loc) · 1.73 KB

global-json-in-effect.md

File metadata and controls

66 lines (54 loc) · 1.73 KB

globalJsonInEffect

Warns when using JSON.parse or JSON.stringify inside Effect generators instead of Effect Schema

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

Preview

import { Effect } from "effect"

export const preview = Effect.gen(function*() {
  const text = yield* Effect.succeed('{"ok":true}')
  return JSON.parse(text)
/**
         ^^^^^^^^^^^^^^^^ effecttsgo(global-json-in-effect): This Effect code uses `JSON.parse`, which throws instead of failing with a typed error. Use `Schema.fromJsonString(Schema.Unknown)` for unknown shapes, `Schema.fromJsonString(schema)` for known ones, or `Schema.toCodecJson(schema)` when working with JSON values instead of strings.
*/
})

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": {
          "globalJsonInEffect": "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-json-in-effect": "warn"
  }
}