Skip to content

Latest commit

 

History

History
78 lines (66 loc) · 1.88 KB

scope-in-layer-effect.md

File metadata and controls

78 lines (66 loc) · 1.88 KB

scopeInLayerEffect

Suggests using Layer.scoped instead of Layer.effect when Scope is in requirements

Property Value
Category Anti-pattern
Default severity warning
Fixable Yes
Effect versions v3
Diagnostic codes TS377031
Language Service name scopeInLayerEffect
Oxlint name effecttsgo/scope-in-layer-effect

Preview

import * as Context from "effect/Context"
import * as Effect from "effect/Effect"
import * as Layer from "effect/Layer"

class Cache extends Context.Tag("Cache")<Cache, { ok: true }>() {}
export const preview = Layer.effect(Cache, Effect.gen(function*() {
/**
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ effecttsgo(scope-in-layer-effect): This layer construction leaves `Scope` in the requirement set. The scoped API removes `Scope` from the resulting requirements.
*/
  yield* Effect.addFinalizer(() => Effect.void)
/**
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
  return { ok: true as const }
/**
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
}))
/**
^^^
*/

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": {
          "scopeInLayerEffect": "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/scope-in-layer-effect": "warn"
  }
}