Linter (oxlint)
Oxlint 的設計目標是在預設情況下捕捉錯誤或無用的程式碼,而無需任何設定。
資訊
在現階段,oxlint 並非旨在完全取代 ESLint;當 ESLint 的速度成為您工作流程中的瓶頸時,它可作為一種增強功能。
我們建議在您的 lint-staged 或 CI 設定中,於 ESLint 之前執行 oxlint,以獲得更快的反饋迴路,因為它在大規模程式碼庫上只需幾秒鐘即可執行完成。
功能
- 比 ESLint 快 50 - 100 倍,並隨著 CPU 核心數量擴展(基準測試)。
- 超過 400 個規則,並且持續從
eslint
、typescript
、eslint-plugin-react
、eslint-plugin-jest
、eslint-plugin-unicorn
、eslint-plugin-jsx-a11y
和 更多 擴增中。 - 支援
- .eslintignore.
- ESLint 註解停用.
- 部分 ESLint v8 設定,使用
json
格式
語言支援
- 支援
- 透過副檔名
js
、mjs
、cjs
、jsx
、ts
、mts
、cts
和tsx
支援 JavaScript 和 TypeScript。 .vue
、.astro
和.svelte
檔案的<script>
內容。
- 透過副檔名
- 不支援
安裝
直接在您的儲存庫根目錄執行 oxlint
sh
$ npx oxlint@latest
sh
$ pnpm dlx oxlint@latest
sh
$ yarn dlx oxlint@latest
sh
$ bunx oxlint@latest
sh
$ deno run npm:oxlint@latest
或將其儲存到您的 package.json
sh
$ npm add -D oxlint
sh
$ pnpm add -D oxlint
sh
$ yarn add -D oxlint
sh
$ bun add -D oxlint
oxlint
不需要 Node.js,可以從最新的 GitHub 版本下載二進制檔案。
命令列介面
請參閱命令列介面
設定檔
請參閱設定檔
整合
ESLint
如果您正在尋找一種在仍需要 ESLint 的專案中使用 oxlint 的方法,可以使用eslint-plugin-oxlint來關閉 oxlint 已經支援的 ESLint 規則。這樣您就可以在仍然使用 ESLint 的同時享受 oxlint 的速度。
lint-staged
json
{
"lint-staged": {
"**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,vue,astro,svelte}": "oxlint"
}
}
VSCode 擴充功能
從以下位置下載官方 VSCode 擴充功能
Zed 擴充功能
https://zed.dev.org.tw/extensions?q=oxc
持續整合
由於 oxlint
只需要幾秒鐘即可執行,我們建議在 ESLint 之前執行 oxlint
以獲得更快的反饋迴路。
GitHub Actions
yaml
jobs:
oxlint:
name: Lint JS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npx --yes oxlint@0.0.0 --deny-warnings # change to the latest release
建議鎖定版本,否則 CI 在新版本發布後可能會失敗。
pre-commit
yaml
repos:
- repo: https://github.com/oxc-project/mirrors-oxlint
rev: v0.0.0 # change to the latest version
hooks:
- id: oxlint
verbose: true
Unplugin
https://www.npmjs.com/package/unplugin-oxlint
Vite 外掛
https://www.npmjs.com/package/vite-plugin-oxlint
系統需求
oxlint
是為 darwin-arm64、darwin-x64、linux-arm64、linux-x64、win32-arm64 和 win32-x64 建置。