Skip to content

Latest commit

 

History

History
71 lines (57 loc) · 2.07 KB

provide-merge-all-to-array.md

File metadata and controls

71 lines (57 loc) · 2.07 KB

provideMergeAllToArray

Suggests passing an array of layers to Effect.provide instead of wrapping them in Layer.mergeAll

Property Value
Category Style
Default severity off
Fixable Yes
Effect versions v3, v4
Diagnostic codes TS377161
Language Service name provideMergeAllToArray
Oxlint name effecttsgo/provide-merge-all-to-array

Preview

import { Context, Effect, Layer } from "effect"

class Db extends Context.Service<Db, { readonly query: (sql: string) => Effect.Effect<string> }>()("Db") {}
class Logger extends Context.Service<Logger, { readonly log: (line: string) => Effect.Effect<void> }>()("Logger") {}

declare const DbLayer: Layer.Layer<Db>
declare const LoggerLayer: Layer.Layer<Logger>
declare const program: Effect.Effect<void, never, Db | Logger>

// MUST TRIGGER: Effect.provide already merges an array of layers
export const main = program.pipe(Effect.provide(Layer.mergeAll(DbLayer, LoggerLayer)))
/**
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ effecttsgo(provide-merge-all-to-array): Effect.provide accepts an array of layers and merges them itself; pass the layers as an array instead of wrapping them in Layer.mergeAll.
*/

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": {
          "provideMergeAllToArray": "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/provide-merge-all-to-array": "warn"
  }
}