Skip to content

Latest commit

 

History

History
71 lines (57 loc) · 1.83 KB

map-some-catch-no-such-element.md

File metadata and controls

71 lines (57 loc) · 1.83 KB

mapSomeCatchNoSuchElement

Suggests Effect.catchNoSuchElement instead of wrapping successes in Option.some and catching NoSuchElementError into Option.none

Property Value
Category Style
Default severity suggestion
Fixable Yes
Effect versions v4
Diagnostic codes TS377167
Language Service name mapSomeCatchNoSuchElement
Oxlint name effecttsgo/map-some-catch-no-such-element

Preview

import { Effect, Option } from "effect"

const users = new Map<string, { readonly name: string }>()

const findUser = (id: string) => Effect.fromNullishOr(users.get(id))

export const lookupUser = (id: string) =>
  findUser(id).pipe(
    Effect.map(Option.some),
    Effect.catchTag("NoSuchElementError", () => Effect.succeed(Option.none()))
/**
    ^^^^^^^^^^^^^^^ effecttsgo(map-some-catch-no-such-element): Use Effect.catchNoSuchElement instead of wrapping successes in Option.some and catching NoSuchElementError into Option.none.
*/
  )

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": {
          "mapSomeCatchNoSuchElement": "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/map-some-catch-no-such-element": "warn"
  }
}