Skip to content

Commit 9a39b11

Browse files
authored
Add Oxlint to project (#218)
1 parent a855cfb commit 9a39b11

File tree

14 files changed

+601
-240
lines changed

14 files changed

+601
-240
lines changed

.github/workflows/lint.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
types: [ opened, synchronize, reopened ]
6+
7+
permissions: { }
8+
env:
9+
CI: 'true'
10+
DO_NOT_TRACK: '1'
11+
NEXT_TELEMETRY_DISABLED: '1'
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
15+
16+
jobs:
17+
lint:
18+
name: Lint app
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
pull-requests: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Setup pnpm
29+
uses: pnpm/action-setup@v4
30+
with:
31+
run_install: false
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version-file: .node-version
36+
cache: 'pnpm'
37+
38+
- name: Install dependencies
39+
run: pnpm install --frozen-lockfile
40+
- uses: oxc-project/[email protected]
41+
with:
42+
config: .oxlintrc.json
43+
- name: Run lint and capture output
44+
id: lint
45+
shell: bash
46+
run: |
47+
set -o pipefail
48+
pnpm run lint 2>&1 | tee lint-output.txt
49+
echo "exit_code=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT
50+
continue-on-error: true
51+
- name: Comment lint results on PR
52+
if: ${{ !cancelled() }}
53+
uses: actions/github-script@v7
54+
with:
55+
script: |
56+
const fs = require('fs');
57+
const output = fs.readFileSync('lint-output.txt', 'utf8');
58+
const exitCode = '${{ steps.lint.outputs.exit_code }}';
59+
const title = exitCode === '0' ? '✅ Lint passed' : '❌ Lint found issues';
60+
const marker = '<!-- lint-report:adev-nextjs-blog -->';
61+
const body = `${marker}\n### ${title}\n\n<details><summary>Show output</summary>\n\n\`\`\`\n${output.slice(-60000)}\n\`\`\`\n\n</details>`;
62+
const { owner, repo } = context.repo;
63+
const issue_number = context.issue.number;
64+
if (!issue_number) {
65+
core.info('No pull request context detected, skipping comment.');
66+
} else {
67+
// Find existing comment with the marker and update it; otherwise create a new one
68+
const comments = await github.paginate(github.rest.issues.listComments, {
69+
owner,
70+
repo,
71+
issue_number,
72+
per_page: 100,
73+
});
74+
const existing = comments.find(c => typeof c.body === 'string' && c.body.includes(marker));
75+
if (existing) {
76+
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
77+
} else {
78+
await github.rest.issues.createComment({ owner, repo, issue_number, body });
79+
}
80+
}
81+
- name: Fail if lint failed
82+
if: steps.lint.outputs.exit_code != '0' && !cancelled()
83+
run: exit ${{ steps.lint.outputs.exit_code }}
84+
- name: Build
85+
run: pnpm run build --no-lint
86+
env:
87+
SKIP_T3_ENV_VALIDATION: 'true'

.oxlintrc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$schema": "./node_modules/oxlint/configuration_schema.json",
3+
"plugins": [
4+
"jsx-a11y",
5+
"nextjs",
6+
"import",
7+
"react",
8+
"typescript",
9+
"unicorn",
10+
"oxc"
11+
],
12+
"env": {
13+
"builtin": true
14+
},
15+
"ignorePatterns": [
16+
"node_modules/**",
17+
".next/**",
18+
"out/**",
19+
"build/**",
20+
"next-env.d.ts"
21+
]
22+
}

eslint.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { dirname } from 'path';
66
import { fileURLToPath } from 'url';
77
import { FlatCompat } from '@eslint/eslintrc';
88
import eslintConfigPrettier from 'eslint-config-prettier/flat';
9+
import oxlint from 'eslint-plugin-oxlint';
910
// import pluginQuery from '@tanstack/eslint-plugin-query';
1011

1112
const __filename = fileURLToPath(import.meta.url);
@@ -20,6 +21,15 @@ const eslintConfig = ts.config(
2021
...compat.extends(
2122
'next/core-web-vitals' /*, 'next/typescript'*/ /*added by ts below*/,
2223
),
24+
{
25+
ignores: [
26+
'node_modules/**',
27+
'.next/**',
28+
'out/**',
29+
'build/**',
30+
'next-env.d.ts',
31+
],
32+
},
2333
...ts.configs.strictTypeChecked,
2434
...ts.configs.stylisticTypeChecked,
2535
eslintConfigPrettier,
@@ -72,6 +82,7 @@ const eslintConfig = ts.config(
7282
// ],
7383
},
7484
},
85+
...oxlint.buildFromOxlintConfigFile('./.oxlintrc.json'), // oxlint should be the last one
7586
);
7687

7788
export default eslintConfig;

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"dev:sw": "next dev --experimental-https",
1212
"build": "next build",
1313
"start": "next start",
14-
"lint": "eslint .",
15-
"lint:fix": "eslint --fix .",
14+
"lint": "pnpm exec oxlint && eslint .",
15+
"lint:fix": "pnpm exec oxlint --fix && eslint --fix .",
1616
"fmt": "prettier --check .",
1717
"fmt:fix": "prettier --write .",
1818
"renovate:debug": "LOG_LEVEL=debug pnpx renovate --platform=local",
@@ -58,6 +58,8 @@
5858
"eslint": "9.33.0",
5959
"eslint-config-next": "15.5.0",
6060
"eslint-config-prettier": "10.1.8",
61+
"eslint-plugin-oxlint": "1.11.2",
62+
"oxlint": "1.11.2",
6163
"prettier": "3.6.2",
6264
"prettier-plugin-tailwindcss": "0.6.14",
6365
"tailwindcss": "4.1.12",

0 commit comments

Comments
 (0)