@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

configuration

by default, the config shared by @magic/lint is used (src/oxlint.config.ts 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

  • [object Object] — 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  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. returns { code, stdout, stderr }.

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, sharedConfigPath, consumerConfigName, config
  • @magic/lint/bin — CLI entry point
  • @magic/lint/config — the shared oxlint config (TS 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