Aller au contenu

OxC oxlint Cheat Sheet

Overview

oxlint is an extremely fast JavaScript/TypeScript linter written in Rust, part of the OxC (Oxidation Compiler) project. It is designed to be a drop-in complement or replacement for ESLint, running 50-100x faster by leveraging Rust’s performance and a purpose-built parser. oxlint supports hundreds of ESLint rules out of the box with zero configuration required, making it ideal for catching obvious issues quickly in large codebases.

The OxC project aims to build a collection of high-performance JavaScript/TypeScript tools in Rust, with oxlint being its most mature component. It supports rules from popular ESLint plugins including eslint-plugin-import, eslint-plugin-jest, eslint-plugin-react, eslint-plugin-jsx-a11y, eslint-plugin-typescript, and more. oxlint is designed to run alongside ESLint or as a faster alternative for the rules it covers.

Installation

npm / Package Managers

# npm
npm install -D oxlint

# pnpm
pnpm add -D oxlint

# yarn
yarn add -D oxlint

# bun
bun add -D oxlint

# Global install
npm install -g oxlint

Standalone Binary

# macOS
brew install oxlint

# Linux / macOS (curl)
curl -sSfL https://oxc.rs/install.sh | sh

# Cargo
cargo install oxlint

Verify Installation

oxlint --version
oxlint --help

Basic Usage

Running the Linter

# Lint current directory
oxlint .

# Lint specific files/directories
oxlint src/
oxlint src/index.ts src/utils.ts
oxlint "src/**/*.{ts,tsx}"

# With specific config
oxlint -c .oxlintrc.json

# Fix auto-fixable issues
oxlint --fix

# Output formats
oxlint --format default    # Human-readable (default)
oxlint --format json       # JSON output
oxlint --format unix       # Unix-style (file:line:col)
oxlint --format github     # GitHub Actions annotations
oxlint --format checkstyle # Checkstyle XML

Common CLI Flags

FlagDescriptionExample
-c, --configConfig file path-c .oxlintrc.json
--fixApply auto-fixesoxlint --fix
--denySet rule to error--deny no-debugger
--warnSet rule to warn--warn no-console
--allowDisable a rule--allow no-unused-vars
-DShort for --deny-D correctness
-WShort for --warn-W suspicious
-AShort for --allow-A restriction
--formatOutput format--format json
--quietOnly show errors--quiet
--max-warningsFail above threshold--max-warnings 10
--ignore-pathIgnore file path--ignore-path .gitignore
--ignore-patternGlob pattern to skip--ignore-pattern "dist/**"
--threadsThread count--threads 4

Rule Categories

Category Flags

# Enable all correctness rules (default: deny)
oxlint -D correctness

# Warn on suspicious patterns
oxlint -W suspicious

# Enable pedantic rules
oxlint -W pedantic

# Enable style rules
oxlint -W style

# Enable restriction rules (opinionated)
oxlint -W restriction

# Enable nursery rules (experimental)
oxlint -W nursery

# Combine categories
oxlint -D correctness -W suspicious -W pedantic

Rule Categories Explained

CategoryLevelDescription
correctnessdenyDefinite bugs and errors
suspiciousoffCode that is likely wrong
pedanticoffOpinionated but useful rules
styleoffCode style preferences
restrictionoffRestrictive / opinionated rules
nurseryoffExperimental / new rules
perfoffPerformance-related rules

Common Rules by Plugin

# ESLint core rules
oxlint -D no-debugger
oxlint -D no-unused-vars
oxlint -D no-console
oxlint -D eqeqeq

# TypeScript rules
oxlint -D @typescript-eslint/no-explicit-any
oxlint -D @typescript-eslint/no-unused-vars

# React rules
oxlint -D react/jsx-no-duplicate-props
oxlint -D react/no-direct-mutation-state
oxlint -W react-hooks/exhaustive-deps

# Import rules
oxlint -D import/no-duplicates
oxlint -D import/no-self-import

# Accessibility rules
oxlint -D jsx-a11y/alt-text
oxlint -D jsx-a11y/no-autofocus

# Jest rules
oxlint -D jest/no-disabled-tests
oxlint -D jest/valid-expect

Configuration

.oxlintrc.json

{
  "$schema": "https://raw.githubusercontent.com/nicolo-ribaudo/oxc/json-schema/npm/oxlint/configuration_schema.json",
  "rules": {
    "no-debugger": "error",
    "no-console": "warn",
    "no-unused-vars": "error",
    "eqeqeq": "error",
    "no-var": "error",
    "prefer-const": "warn",
    "@typescript-eslint/no-explicit-any": "warn",
    "react/jsx-no-duplicate-props": "error",
    "react-hooks/exhaustive-deps": "warn",
    "import/no-duplicates": "error",
    "jsx-a11y/alt-text": "error"
  },
  "settings": {
    "jsx-runtime": "automatic"
  },
  "env": {
    "browser": true,
    "node": true,
    "es2024": true
  },
  "globals": {
    "__DEV__": "readonly",
    "process": "readonly"
  },
  "ignorePatterns": [
    "dist",
    "build",
    "node_modules",
    "coverage",
    "*.min.js"
  ]
}

Inline Directives

// Disable for next line
// oxlint-disable-next-line no-console
console.log("debug");

// Disable for this line
console.log("debug"); // oxlint-disable-line no-console

// Disable for block
/* oxlint-disable no-console */
console.log("a");
console.log("b");
/* oxlint-enable no-console */

// ESLint directives also work
// eslint-disable-next-line no-console
console.log("debug");

Integration

package.json Scripts

{
  "scripts": {
    "lint": "oxlint .",
    "lint:fix": "oxlint --fix .",
    "lint:ci": "oxlint --format github --max-warnings 0 .",
    "lint:check": "oxlint --quiet ."
  }
}

CI/CD Integration

# GitHub Actions
name: Lint
on: [push, pull_request]
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: oxc-project/oxlint-action@v0
        with:
          args: --deny correctness --warn suspicious

Pre-commit Hook

# Using lint-staged
npm install -D lint-staged husky

# package.json
{
  "lint-staged": {
    "*.{js,ts,jsx,tsx}": "oxlint --fix"
  }
}

VS Code Extension

// .vscode/settings.json
{
  "oxc.lint.enable": true,
  "oxc.lint.run": "onType",
  "oxc.configPath": ".oxlintrc.json"
}

Advanced Usage

Running Alongside ESLint

# Use oxlint for fast rules, ESLint for complex ones
# In package.json
{
  "scripts": {
    "lint": "oxlint . && eslint .",
    "lint:fix": "oxlint --fix . && eslint --fix ."
  }
}
// .eslintrc.js - Disable rules covered by oxlint
module.exports = {
  // ... your config
  rules: {
    // These are handled by oxlint (faster)
    "no-debugger": "off",
    "no-unused-vars": "off",
    "no-console": "off",
    // Keep ESLint for rules oxlint doesn't cover
    "import/order": "error",
  }
};

Monorepo Setup

# Lint entire monorepo
oxlint .

# Lint specific packages
oxlint packages/app packages/lib

# Ignore patterns for monorepo
oxlint . --ignore-pattern "packages/*/dist" --ignore-pattern "packages/*/node_modules"

Performance Benchmarking

# Time the linter
time oxlint .

# With thread control
oxlint --threads 1 .   # Single-threaded for comparison
oxlint --threads 8 .   # Multi-threaded

# Compare with ESLint
time npx eslint .
time oxlint .

Troubleshooting

ProblemSolution
Rule not recognizedCheck if rule is supported: oxlint --help or docs
False positivesUse inline directives to suppress; report to OxC project
Config not loadingCheck file name is .oxlintrc.json; verify JSON syntax
Fix not workingNot all rules have auto-fixes; check rule documentation
ESLint directives ignoredMost eslint-disable comments work; some may not
TypeScript parsing errorsEnsure .ts/.tsx extensions; check for syntax errors
Performance not as expectedCheck file count; ensure node_modules is ignored
Missing plugin rulesoxlint has built-in plugins; no separate installs needed