OXC.Lint (OXC v0.11.0)

Copy Markdown View Source

Lint JavaScript/TypeScript source with oxlint's built-in rules and optional custom Elixir rules.

Combines native Rust performance for 650+ standard rules with the ability to write project-specific rules in Elixir using the same AST that OXC.parse/2 returns.

Examples

{:ok, diags} = OXC.Lint.run("debugger;", "test.js",
  rules: %{"no-debugger" => :deny})

{:ok, []} = OXC.Lint.run("export const x = 1;\n", "test.ts")

Summary

Functions

Lint source code with oxlint's built-in rules and optional custom rules.

Like run/3 but raises on errors.

Types

diagnostic()

@type diagnostic() :: %{
  rule: String.t(),
  message: String.t(),
  severity: severity(),
  span: {non_neg_integer(), non_neg_integer()},
  labels: [{non_neg_integer(), non_neg_integer()}],
  help: String.t() | nil
}

severity()

@type severity() :: :allow | :warn | :deny

Functions

run(source, filename, opts \\ [])

@spec run(String.t(), String.t(), keyword()) ::
  {:ok, [diagnostic()]} | {:error, [String.t()]}

Lint source code with oxlint's built-in rules and optional custom rules.

Options

  • :rules — map of rule names to severity (:deny, :warn, :allow). Rule names follow oxlint conventions: "eqeqeq", "react/no-danger", "typescript/no-explicit-any", etc.

  • :plugins — list of built-in plugin atoms to enable. Default: oxlint defaults (eslint correctness rules). Available: :react, :typescript, :unicorn, :import, :jsdoc, :jest, :vitest, :jsx_a11y, :nextjs, :react_perf, :promise, :node, :vue, :oxc

  • :fix — compute fix suggestions. Default: false

  • :custom_rules — list of {module, severity} tuples for Elixir rules. Each module must implement the OXC.Lint.Rule behaviour.

  • :settings — arbitrary map passed to custom rule context.

Examples

# Built-in rules only
{:ok, diags} = OXC.Lint.run("debugger;", "test.js",
  rules: %{"no-debugger" => :deny})

# With specific plugins and rules
{:ok, diags} = OXC.Lint.run(source, "app.tsx",
  plugins: [:react, :typescript],
  rules: %{"no-console" => :warn, "react/no-danger" => :deny}
)

# With custom Elixir rules
{:ok, diags} = OXC.Lint.run(source, "app.ts",
  custom_rules: [{MyApp.NoConsoleLog, :warn}]
)

run!(source, filename, opts \\ [])

@spec run!(String.t(), String.t(), keyword()) :: [diagnostic()]

Like run/3 but raises on errors.