Skip to content

Latest commit

 

History

History
73 lines (59 loc) · 1.86 KB

option-match-to-from-option.md

File metadata and controls

73 lines (59 loc) · 1.86 KB

optionMatchToFromOption

Suggests Effect.fromOption when Option.match or an Option tag conditional only converts Some to Effect.succeed and None to Effect.fail

Property Value
Category Style
Default severity suggestion
Fixable Yes
Effect versions v4
Diagnostic codes TS377118
Language Service name optionMatchToFromOption
Oxlint name effecttsgo/option-match-to-from-option

Preview

import { Data, Effect, Option } from "effect"

class UserNotFound extends Data.TaggedError("UserNotFound")<{
  readonly id: string
}> {}

declare const findUser: (id: string) => Option.Option<{ readonly name: string }>

export const getUser = (id: string) =>
  Option.match(findUser(id), {
/**
  ^^^^^^^^^^^^ effecttsgo(option-match-to-from-option): `Effect.fromOption` expresses this Option-to-Effect conversion more directly than `Option.match` or an Option tag conditional.
*/
    onNone: () => Effect.fail(new UserNotFound({ id })),
    onSome: (user) => Effect.succeed(user)
  })

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": {
          "optionMatchToFromOption": "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/option-match-to-from-option": "warn"
  }
}