Today I added Oxlint to my Node.js project Codeshift.
Oxlint is a linter designed to catch erroneous or useless code without requiring any configurations by default. Although I already had Prettier and ESLint set up, Oxlint is much faster - the docs claim it's 50 - 100 times faster than ESLint - and it scales with the number of CPU cores.
Setting it up was simple.
-
I installed it:
npm i -D oxlint
-
To configure it to work together with ESLint, I installed eslint-plugin-oxlint.
npm i -D eslint-plugin-oxlint
-
I added the ESLint plugin to
eslint.config.mjs
:
// eslint.config.js import oxlint from 'eslint-plugin-oxlint'; export default [ ...// other plugins oxlint.configs['flat/recommended'], // oxlint should be the last one ];
-
I updated my
lint
script inpackage.json
to run Oxlint before ESLint:
"scripts": { "lint": "oxlint && eslint" }
-
I added it to my pre-commit hook using lint-staged in
package.json
:
"lint-staged": { "**/*.": [ "oxlint", "prettier --write --ignore-unknown", "eslint" ] },
-
I added it to my CI workflow:
jobs: build: steps: - run: npx -y oxlint@0.10.3 --deny-warnings
-
I added the Oxc VSCode extension to my project's workspace extension recommendations:
// .vscode/extensions.json { "recommendations": [ "dbaeumer.vscode-eslint", "streetsidesoftware.code-spell-checker", "esbenp.prettier-vscode", "oxc.oxc-vscode" ] }
While I was doing this, I also added a script to run Prettier in package.json, which I didn't realize was missing.
```json
"scripts": {
"format": "prettier --write ."
}
```
I updated our contributing docs to mention running the lint and format scripts before committing. I also added VSCode workspace editor settings to match Prettier's default settings.
```
// .vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.fixAll": "always",
"source.organizeImports": "always"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.tabSize": 2,
"files.eol": "\n",
"files.insertFinalNewline": true,
"cSpell.words": ["codeshift", "openai", "oxlint", "smol"]
}
```
I tested out my changes and Oxlint ran fine, and found nothing wrong with my code. Although for some reason, when I pushed my code, the CI job failed because Prettier didn't run on commit. I'll have to look into this further.
It was interesting setting this stuff up. I learned that I've been setting up lint-staged wrong in my projects and was running Prettier and ESLint concurrently, which would lead to race conditions.
I also deleted my .prettierignore
because Prettier follows the rules in .gitignore
and I realized it was redundant.
Oxc, Oxlint's parent project, also has a formatter, but I chose not to use it because it's still a prototype and doesn't have docs.
That's it for this post. Thanks for reading!
Top comments (0)