Skip to content

Commit c9504ce

Browse files
dvcolombanyuyinws
andauthored
fix(oxc): tolerate stdout notices ahead of oxlint's JSON payload (#476)
* fix(oxc): tolerate stdout notices ahead of oxlint's JSON payload Oxlint can print human-readable notices (e.g. "No files found to lint...") to stdout before the JSON payload even when run with `-f json` — this happens for any project where oxlint's default file discovery matches zero files (e.g. a package that isn't opted into oxlint in a monorepo with a default-deny root config). `parseOxlintOutput` called `JSON.parse` on the raw stdout, so that leading notice broke parsing and the lint-run RPC failed with "Oxlint returned invalid JSON" instead of reporting zero diagnostics. * fix(oxc): bridge RPC during local development --------- Co-authored-by: yuyinws <lyc657508366@gmail.com>
1 parent 6100cfa commit c9504ce

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

packages/oxc/src/node/__tests__/lint-results.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,21 @@ it('accepts the null rule count emitted by recent oxlint versions', async () =>
106106
),
107107
).resolves.toMatchObject({ summary: { number_of_rules: null } })
108108
})
109+
110+
it('skips the "no files found" notice oxlint prints to stdout ahead of the JSON payload', async () => {
111+
const root = await createFixture()
112+
const rawOutput = [
113+
'No files found to lint. Please check your paths and ignore patterns.',
114+
JSON.stringify({
115+
diagnostics: [],
116+
number_of_files: 0,
117+
number_of_rules: 95,
118+
threads_count: 11,
119+
start_time: 0.03,
120+
}),
121+
].join('\n')
122+
123+
await expect(parseOxlintOutput(rawOutput, root)).resolves.toMatchObject({
124+
summary: { number_of_files: 0 },
125+
})
126+
})

packages/oxc/src/node/utils/oxlint.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ export async function ensureOxcGitignored(root: string) {
4141
}
4242

4343
export async function parseOxlintOutput(rawOutput: string, root: string) {
44-
const data = JSON.parse(rawOutput) as Record<string, unknown>
44+
// Oxlint can print human-readable notices (e.g. "No files found to lint...") to stdout
45+
// ahead of the JSON payload even in `-f json` mode. Skip to the first `{` so those notices
46+
// don't break parsing.
47+
const jsonStart = rawOutput.indexOf('{')
48+
const data = JSON.parse(jsonStart === -1 ? rawOutput : rawOutput.slice(jsonStart)) as Record<
49+
string,
50+
unknown
51+
>
4552
const summaryFields = [
4653
'number_of_files',
4754
'number_of_rules',

packages/oxc/src/nuxt.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { fileURLToPath } from 'node:url'
2+
import { viteDevBridge } from 'devframe/helpers/vite'
23
import { defineNuxtConfig } from 'nuxt/config'
34
import { alias } from '../../../alias'
5+
import { oxcDevframe } from './node/devframe'
46

57
const BASE = '/__devtools-oxc/'
68

@@ -56,6 +58,9 @@ export default defineNuxtConfig({
5658
},
5759
vite: {
5860
base: BASE,
61+
plugins: [
62+
viteDevBridge({ ...oxcDevframe, basePath: '/' }, { base: BASE, devMiddleware: true }),
63+
],
5964
optimizeDeps: {
6065
include: ['modern-monaco', 'floating-vue'],
6166
},

0 commit comments

Comments
 (0)