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
3 changes: 2 additions & 1 deletion apps/oxlint/src-js/plugins/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export class Context {

// Getter for full rule name, in form `<plugin>/<rule>`
get id() {
return getInternal(this, 'access `context.id`').id;
// Note: We can allow accessing `id` in `createOnce`, as it's not file-specific. So skip `getInternal` call.
return this.#internal.id;
}

// Getter for absolute path of file being linted.
Expand Down
4 changes: 2 additions & 2 deletions apps/oxlint/test/fixtures/createOnce/output.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
: ^
`----

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

x create-once-plugin(always-run): createOnce: id: Cannot access `context.id` in `createOnce`
x create-once-plugin(always-run): createOnce: id: create-once-plugin/always-run
,-[files/2.js:1:1]
1 | let y;
: ^
Expand Down
5 changes: 3 additions & 2 deletions apps/oxlint/test/fixtures/createOnce/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const alwaysRunRule: Rule = {
// oxlint-disable-next-line typescript-eslint/no-this-alias
const topLevelThis = this;

const { id } = context;

// Check that these APIs throw here
const idError = tryCatch(() => context.id);
const filenameError = tryCatch(() => context.filename);
const physicalFilenameError = tryCatch(() => context.physicalFilename);
const optionsError = tryCatch(() => context.options);
Expand All @@ -35,7 +36,7 @@ const alwaysRunRule: Rule = {
before() {
context.report({ message: `createOnce: call count: ${createOnceCallCount}`, node: SPAN });
context.report({ message: `createOnce: this === rule: ${topLevelThis === alwaysRunRule}`, node: SPAN });
context.report({ message: `createOnce: id: ${idError?.message}`, node: SPAN });
context.report({ message: `createOnce: id: ${id}`, node: SPAN });
context.report({ message: `createOnce: filename: ${filenameError?.message}`, node: SPAN });
context.report({ message: `createOnce: physicalFilename: ${physicalFilenameError?.message}`, node: SPAN });
context.report({ message: `createOnce: options: ${optionsError?.message}`, node: SPAN });
Expand Down
Loading