Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/mpsuesser/effect-oxlint/llms.txt

Use this file to discover all available pages before exploring further.

The Diagnostic module provides structured builders for creating and enhancing oxlint diagnostics. make and fromId construct basic diagnostics from a node location and message. withFix and withSuggestions attach autofix or suggestion metadata. The fix helpers — replaceText, insertBefore, insertAfter, removeFix, and composeFixes — produce composable FixFn values that can be combined freely before attaching to a diagnostic.

Diagnostic.make

Creates a diagnostic with a message and node location.
export const make = (opts: {
  readonly node: Ranged;
  readonly message: string;
  readonly data?: DiagnosticData;
}): OxlintDiagnostic
node
Ranged
required
The AST node or token that the diagnostic points to. Any value with range information satisfies Ranged.
message
string
required
The human-readable diagnostic message shown to the user.
data
DiagnosticData
Optional interpolation data for message templates.
import { Diagnostic } from 'effect-oxlint';

const diag = Diagnostic.make({
  node,
  message: 'Use Schema for JSON decoding instead of JSON.parse'
});

Diagnostic.fromId

Creates a diagnostic using a messageId key from meta.messages rather than an inline string. The oxlint runtime resolves the template at report time.
export const fromId = (opts: {
  readonly node: Ranged;
  readonly messageId: string;
  readonly data?: DiagnosticData;
}): OxlintDiagnostic
node
Ranged
required
The AST node or token that the diagnostic points to.
messageId
string
required
A key from the messages record in Rule.meta. The runtime substitutes it with the corresponding message template.
data
DiagnosticData
Optional interpolation data for the message template.
const myRule = Rule.define({
  name: 'no-clock-direct',
  meta: Rule.meta({
    type: 'problem',
    description: 'Disallow direct Date usage',
    messages: {
      useClockService: 'Use the Clock service instead of {{expr}}'
    }
  }),
  create: function* () {
    const ctx = yield* RuleContext;
    return {
      NewExpression: (node) =>
        Option.match(AST.narrow(node, 'NewExpression'), {
          onNone: () => Effect.void,
          onSome: (n) =>
            ctx.report(
              Diagnostic.fromId({
                node: n,
                messageId: 'useClockService',
                data: { expr: 'new Date()' }
              })
            )
        })
    };
  }
});

Diagnostic.withFix

Attaches an autofix function to a diagnostic. Dual API — supports both data-first and data-last calling conventions.
export const withFix: {
  (fix: FixFn): (diagnostic: OxlintDiagnostic) => OxlintDiagnostic
}
diagnostic
OxlintDiagnostic
required
The diagnostic to attach the fix to.
fix
FixFn
required
A fix function, typically produced by replaceText, insertBefore, insertAfter, removeFix, or composeFixes.
// Data-first
const fixed = Diagnostic.withFix(
  Diagnostic.make({ node, message: 'Avoid this pattern' }),
  Diagnostic.replaceText(node, 'replacement')
)

// Data-last with pipe
const fixed = pipe(
  Diagnostic.make({ node, message: 'Avoid this pattern' }),
  Diagnostic.withFix(Diagnostic.replaceText(node, 'replacement'))
)

Diagnostic.withSuggestions

Attaches suggestion fixes to a diagnostic. Suggestions differ from autofixes in that the user applies them manually. Dual API — supports both data-first and data-last calling conventions.
export const withSuggestions: {
  (
    suggestions: ReadonlyArray<Suggestion>
  ): (diagnostic: OxlintDiagnostic) => OxlintDiagnostic
}
diagnostic
OxlintDiagnostic
required
The diagnostic to attach suggestions to.
suggestions
ReadonlyArray<Suggestion>
required
An array of Suggestion objects, each containing a description and a fix function.
To enable suggestions, set hasSuggestions: true in your Rule.meta call.
const diag = pipe(
  Diagnostic.make({ node, message: 'Prefer Effect.log' }),
  Diagnostic.withSuggestions([
    {
      desc: 'Replace with Effect.log',
      fix: Diagnostic.replaceText(node, 'Effect.log')
    }
  ])
)

Diagnostic.replaceText

Returns a FixFn that replaces the text of a node or token with the given string.
export const replaceText =
  (nodeOrToken: Ranged, text: string): FixFn
nodeOrToken
Ranged
required
The node or token whose source text should be replaced.
text
string
required
The replacement text.
Diagnostic.replaceText(node, 'Effect.log')

Diagnostic.insertBefore

Returns a FixFn that inserts text immediately before a node or token.
export const insertBefore =
  (nodeOrToken: Ranged, text: string): FixFn
nodeOrToken
Ranged
required
The node or token to insert text before.
text
string
required
The text to insert.
Diagnostic.insertBefore(node, 'await ')

Diagnostic.insertAfter

Returns a FixFn that inserts text immediately after a node or token.
export const insertAfter =
  (nodeOrToken: Ranged, text: string): FixFn
nodeOrToken
Ranged
required
The node or token to insert text after.
text
string
required
The text to insert.
Diagnostic.insertAfter(node, ' as const')

Diagnostic.removeFix

Returns a FixFn that removes a node or token from the source.
export const removeFix =
  (nodeOrToken: Ranged): FixFn
nodeOrToken
Ranged
required
The node or token to remove.
Diagnostic.removeFix(node)

Diagnostic.composeFixes

Composes multiple FixFn values into a single FixFn. All individual fixes are collected into a single array result, letting you apply several edits atomically.
export const composeFixes =
  (...fixes: ReadonlyArray<FixFn>): FixFn
fixes
ReadonlyArray<FixFn>
required
Any number of fix functions to compose. All are applied when the composed fix runs.
// Wrap a node with a function call: prefix + suffix
const multiFix = Diagnostic.composeFixes(
  Diagnostic.insertBefore(node, 'Effect.succeed('),
  Diagnostic.insertAfter(node, ')')
)

const diag = pipe(
  Diagnostic.make({ node, message: 'Wrap in Effect.succeed' }),
  Diagnostic.withFix(multiFix)
)
All fix helpers return plain FixFn values. You can store them in variables, pass them as arguments, or compose them before attaching to a diagnostic — they carry no side effects until oxlint applies the fix.

Build docs developers (and LLMs) love