@magic/lint

@magic/lint

run oxlint and lint your code.

install

be in a nodejs project.

npm i --save-dev --save-exact @magic/lint

usage

npm scripts

{  "scripts": {    "lint": "lint"  }}

then run:

npm run lintnpm run lint srcnpm run lint -f

cli

lint [paths]     - lint the given paths, or the current directorylint -c conf.ts  - lint with the given configlint -f          - fix as many issues as possiblelint -v          - echo the oxlint command

oxlint

colors

oxlint only emits colors when its own stdout is a TTY, so piping its output (which lint always does) would lose them. lint therefore decides on color from its own stdout and passes the decision to oxlint via its environment, so npm run lint in a terminal shows the same colored output as running oxlint directly, while lint | tee log.txt stays plain.

the decision respects the standard env vars, in this order of precedence:

  • NO_COLOR (set and non-empty) — no colors, even in a TTY
  • FORCE_COLOR (set, not 0) — colors, even when piped
  • lint's stdout is a TTY — colors
  • CI (set and non-empty) — colors, for CI logs
  • otherwise — no colors

configuration

by default, the config shared by @magic/lint is used (src/oxlint.config.js of this package).

if your project has an oxlint.config.ts in its root (process.cwd()), it is used instead, so you can tailor the rules to your codebase.

a different config can be given explicitly with --config.

config resolution order

lint resolves the config in this order:

  • explicit --config / -c flag — passed through as-is (relative paths resolved against cwd)
  • consumer config — oxlint.config.ts in the current working directory (if it exists)
  • shared config — the built-in config from @magic/lint (fallback)

this means you can:

  • run lint with zero config in a new project (uses shared config)
  • add oxlint.config.ts to your project to customize rules
  • run lint -c my.config.ts for one-off configs (e.g. CI, sub-projects)

extending the shared config

instead of replacing the shared config, extend it from your own oxlint.config.ts. import the shared config via the /config export and re-export it. this is **mandatory** for oxlint to find and apply the correct rules to your files:

// oxlint.config.tsimport config from '@magic/lint/config'export default config

without this import/export, oxlint will not pick up your custom configuration and will not find the files correctly. your project oxlint.config.ts is picked up automatically by lint once you re-export the shared config, so no extra wiring is needed.

environment variables

  • MAGIC_LINT_OXLINT_BIN — override the oxlint binary path (for testing or custom builds)

javascript api

the javascript api provides low-level utilities for running oxlint programmatically:

import {  resolveConfig,      // resolve config path given args + cwd  getOxlintBin,       // get the oxlint binary path  runOxlint,          // run oxlint with raw args  colorEnv,           // env for oxlint color output, see colors above  sharedConfigPath,   // path to the shared config  consumerConfigName, // 'oxlint.config.ts'  config,             // the shared oxlint config object} from '@magic/lint'

runOxlint(oxlintArgs, cwd)

low-level: spawns oxlint with the given argv array. color is decided via colorEnv(). returns { code, stdout, stderr }.

colorEnv(env, isTTY)

computes the env to pass to an oxlint child process for color output: FORCE_COLOR=1 when color should be emitted, NO_COLOR=1 otherwise. defaults to the current process's env and stdout.

resolveConfig(args, cwd)

resolves the config file path per the resolution order above.

getOxlintBin()

returns the path to the oxlint binary. respects MAGIC_LINT_OXLINT_BIN.

sharedConfigPath

absolute path to this package's src/oxlint.config.js.

consumerConfigName

string 'oxlint.config.ts' — the filename checked in the consumer project.

config

the shared oxlint config object (default export of oxlint.config.js).

package exports

  • @magic/lint — named: resolveConfig, getOxlintBin, runOxlint, colorEnv, sharedConfigPath, consumerConfigName, config
  • @magic/lint/bin — CLI entry point
  • @magic/lint/config — the shared oxlint config (JS module, import and re-export it from your oxlint.config.ts) — **mandatory** for oxlint to find and apply rules to your files
  • @magic/lint/types — TypeScript declarations

exit codes

  • 0 — no issues found
  • 1 — lint issues found, or an oxlint error (e.g. no files matched)

license

LICENSE