From d2ca5400807dacd582b5366b2db57cf14c7715cd Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Thu, 4 Dec 2025 16:39:55 +0000 Subject: [PATCH] feat(linter/plugins): add `SourceCode#isESTree` property (#16499) Add `isESTree` property to `SourceCode`. ESLint's has this property, though it's undocumented. --- apps/oxlint/src-js/plugins/source_code.ts | 6 ++++++ apps/oxlint/test/fixtures/sourceCode/output.snap.md | 4 ++++ apps/oxlint/test/fixtures/sourceCode/plugin.ts | 6 ++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/oxlint/src-js/plugins/source_code.ts b/apps/oxlint/src-js/plugins/source_code.ts index 35c996481d2c8..51c971b02b5e2 100644 --- a/apps/oxlint/src-js/plugins/source_code.ts +++ b/apps/oxlint/src-js/plugins/source_code.ts @@ -142,6 +142,12 @@ export const SOURCE_CODE = Object.freeze({ return ast; }, + /** + * `true` if the AST is in ESTree format. + */ + // This property is present in ESLint's `SourceCode`, but is undocumented + isESTree: true, + /** * `ScopeManager` for the file. */ diff --git a/apps/oxlint/test/fixtures/sourceCode/output.snap.md b/apps/oxlint/test/fixtures/sourceCode/output.snap.md index 14d9b6af0f9ae..78a889d991d89 100644 --- a/apps/oxlint/test/fixtures/sourceCode/output.snap.md +++ b/apps/oxlint/test/fixtures/sourceCode/output.snap.md @@ -36,6 +36,7 @@ | 25 => { line: 5, column: 0 }("") | ast: "foo" | visitorKeys: left, right + | isESTree: true ,-[files/1.js:1:1] 1 | let foo, bar; : ^ @@ -83,6 +84,7 @@ | 25 => { line: 5, column: 0 }("") | ast: "foo" | visitorKeys: left, right + | isESTree: true ,-[files/1.js:1:1] 1 | let foo, bar; : ^ @@ -174,6 +176,7 @@ | 9 => { line: 2, column: 0 }("") | ast: "qux" | visitorKeys: left, right + | isESTree: true ,-[files/2.js:1:1] 1 | let qux; : ^ @@ -203,6 +206,7 @@ | 9 => { line: 2, column: 0 }("") | ast: "qux" | visitorKeys: left, right + | isESTree: true ,-[files/2.js:1:1] 1 | let qux; : ^ diff --git a/apps/oxlint/test/fixtures/sourceCode/plugin.ts b/apps/oxlint/test/fixtures/sourceCode/plugin.ts index cf9824c26eddb..f9150ebec4982 100644 --- a/apps/oxlint/test/fixtures/sourceCode/plugin.ts +++ b/apps/oxlint/test/fixtures/sourceCode/plugin.ts @@ -39,7 +39,8 @@ const createRule: Rule = { `locs:${locs}\n` + // @ts-ignore `ast: "${ast.body[0].declarations[0].id.name}"\n` + - `visitorKeys: ${sourceCode.visitorKeys.BinaryExpression.join(", ")}`, + `visitorKeys: ${sourceCode.visitorKeys.BinaryExpression.join(", ")}\n` + + `isESTree: ${sourceCode.isESTree}`, node: SPAN, }); @@ -103,7 +104,8 @@ const createOnceRule: Rule = { `locs:${locs}\n` + // @ts-ignore `ast: "${ast.body[0].declarations[0].id.name}"\n` + - `visitorKeys: ${sourceCode.visitorKeys.BinaryExpression.join(", ")}`, + `visitorKeys: ${sourceCode.visitorKeys.BinaryExpression.join(", ")}\n` + + `isESTree: ${sourceCode.isESTree}`, node: SPAN, }); },