Skip to content

Latest commit

 

History

History
65 lines (52 loc) · 1.75 KB

global-json.md

File metadata and controls

65 lines (52 loc) · 1.75 KB

globalJson

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

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

Preview

import { Schema } from "effect"

const User = Schema.Struct({ name: Schema.String })

export const parseUser = (text: string) => Schema.decodeUnknownSync(User)(JSON.parse(text))
/**
                                                                          ^^^^^^^^^^^^^^^^ effecttsgo(global-json): This 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": {
          "globalJson": "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": "warn"
  }
}