Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/oxlint/src-js/package/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const FILE_CONTEXT: FileContext = Object.freeze({
throw new Error("Cannot access `context.parserOptions` in `createOnce`");
},

get parserPath(): string {
get parserPath(): string | undefined {
throw new Error("Cannot access `context.parserPath` in `createOnce`");
},
});
Expand Down
6 changes: 3 additions & 3 deletions apps/oxlint/src-js/plugins/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ const FILE_CONTEXT = Object.freeze({
* The path to the parser used to parse this file.
* @deprecated No longer supported.
*/
get parserPath(): string {
// TODO: Implement this?
throw new Error("`context.parserPath` is unsupported at present (and deprecated)");
get parserPath(): string | undefined {
if (filePath === null) throw new Error("Cannot access `context.parserPath` in `createOnce`");
return undefined;
},
});

Expand Down
2 changes: 2 additions & 0 deletions apps/oxlint/test/fixtures/context_properties/output.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
| getPhysicalFilename(): <fixture>/files/1.js
| cwd: <fixture>
| getCwd(): <fixture>
| parserPath: undefined
,-[files/1.js:1:1]
1 | let x;
: ^
Expand All @@ -33,6 +34,7 @@
| getPhysicalFilename(): <fixture>/files/2.js
| cwd: <fixture>
| getCwd(): <fixture>
| parserPath: undefined
,-[files/2.js:1:1]
1 | let y;
: ^
Expand Down
3 changes: 2 additions & 1 deletion apps/oxlint/test/fixtures/context_properties/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const rule: Rule = {
`physicalFilename: ${context.physicalFilename}\n` +
`getPhysicalFilename(): ${context.getPhysicalFilename()}\n` +
`cwd: ${context.cwd}\n` +
`getCwd(): ${context.getCwd()}`,
`getCwd(): ${context.getCwd()}\n` +
`parserPath: ${context.parserPath}`,
node: SPAN,
});

Expand Down
14 changes: 13 additions & 1 deletion apps/oxlint/test/fixtures/createOnce/output.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
: ^
`----

x create-once-plugin(always-run): createOnce: parserPath error: Cannot access `context.parserPath` in `createOnce`
,-[files/1.js:1:1]
1 | let x;
: ^
`----

x create-once-plugin(always-run): createOnce: physicalFilename error: Cannot access `context.physicalFilename` in `createOnce`
,-[files/1.js:1:1]
1 | let x;
Expand Down Expand Up @@ -273,6 +279,12 @@
: ^
`----

x create-once-plugin(always-run): createOnce: parserPath error: Cannot access `context.parserPath` in `createOnce`
,-[files/2.js:1:1]
1 | let y;
: ^
`----

x create-once-plugin(always-run): createOnce: physicalFilename error: Cannot access `context.physicalFilename` in `createOnce`
,-[files/2.js:1:1]
1 | let y;
Expand Down Expand Up @@ -351,7 +363,7 @@
: ^
`----

Found 0 warnings and 58 errors.
Found 0 warnings and 60 errors.
Finished in Xms on 2 files with 6 rules using X threads.
```

Expand Down
5 changes: 5 additions & 0 deletions apps/oxlint/test/fixtures/createOnce/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const alwaysRunRule: Rule = {
const getSourceCodeError = tryCatch(() => context.getSourceCode());
const settingsError = tryCatch(() => context.settings);
const parserOptionsError = tryCatch(() => context.parserOptions);
const parserPathError = tryCatch(() => context.parserPath);
const reportError = tryCatch(() => context.report({ message: "oh no", node: SPAN }));

return {
Expand Down Expand Up @@ -84,6 +85,10 @@ const alwaysRunRule: Rule = {
message: `createOnce: parserOptions error: ${parserOptionsError?.message}`,
node: SPAN,
});
context.report({
message: `createOnce: parserPath error: ${parserPathError?.message}`,
node: SPAN,
});
context.report({
message: `createOnce: report error: ${reportError?.message}`,
node: SPAN,
Expand Down
Loading