diff --git a/napi/oxlint2/src-js/index.js b/napi/oxlint2/src-js/index.js index dcf7eb0563fe7..022eb4c638e23 100644 --- a/napi/oxlint2/src-js/index.js +++ b/napi/oxlint2/src-js/index.js @@ -75,6 +75,8 @@ class Context { // Index into `ruleIds` sent from Rust. Set before calling `rule`'s `create` method. #ruleIndex; // Absolute path of file being linted. Set before calling `rule`'s `create` method. + filename; + // Absolute path of file being linted. Set before calling `rule`'s `create` method. physicalFilename; /** @@ -117,6 +119,7 @@ class Context { */ setupContextForFile = (context, ruleIndex, filePath) => { context.#ruleIndex = ruleIndex; + context.filename = filePath; context.physicalFilename = filePath; }; } diff --git a/napi/oxlint2/test/__snapshots__/e2e.test.ts.snap b/napi/oxlint2/test/__snapshots__/e2e.test.ts.snap index 931853a05b2a8..342d6ec55a1b8 100644 --- a/napi/oxlint2/test/__snapshots__/e2e.test.ts.snap +++ b/napi/oxlint2/test/__snapshots__/e2e.test.ts.snap @@ -330,6 +330,12 @@ exports[`oxlint2 CLI > should receive data via \`context\` 1`] = ` : ^ \`---- + x context-plugin(log-context): filename: files/1.js + ,-[files/1.js:1:1] + 1 | let x; + : ^ + \`---- + x context-plugin(log-context): physicalFilename: files/1.js ,-[files/1.js:1:1] 1 | let x; @@ -342,13 +348,19 @@ exports[`oxlint2 CLI > should receive data via \`context\` 1`] = ` : ^ \`---- + x context-plugin(log-context): filename: files/2.js + ,-[files/2.js:1:1] + 1 | let y; + : ^ + \`---- + x context-plugin(log-context): physicalFilename: files/2.js ,-[files/2.js:1:1] 1 | let y; : ^ \`---- -Found 0 warnings and 4 errors. +Found 0 warnings and 6 errors. Finished in Xms on 2 files using X threads." `; diff --git a/napi/oxlint2/test/fixtures/context_properties/test_plugin/index.js b/napi/oxlint2/test/fixtures/context_properties/test_plugin/index.js index 42aaa206bc4df..6582101bab534 100644 --- a/napi/oxlint2/test/fixtures/context_properties/test_plugin/index.js +++ b/napi/oxlint2/test/fixtures/context_properties/test_plugin/index.js @@ -20,6 +20,11 @@ export default { node: SPAN, }); + context.report({ + message: `filename: ${relativePath(context.filename)}`, + node: SPAN, + }); + context.report({ message: `physicalFilename: ${relativePath(context.physicalFilename)}`, node: SPAN,