-
-
Notifications
You must be signed in to change notification settings - Fork 721
refactor(linter/plugins): allow accessing context.id in createOnce
#15447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(linter/plugins): allow accessing context.id in createOnce
#15447
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR allows accessing context.id within the createOnce function by removing the restriction that previously threw an error. Since the rule ID is not file-specific and is initialized at construction time, it's safe to access it in createOnce.
Key Changes
- Modified the
idgetter in theContextclass to bypass thegetInternalvalidation check - Updated test fixtures to verify that
context.idis now accessible increateOnce - Updated snapshot tests to reflect the new behavior showing the actual rule ID instead of an error message
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/oxlint/src-js/plugins/context.ts | Modified the id getter to directly access the internal id property, bypassing the createOnce restriction since the ID is not file-specific |
| apps/oxlint/test/fixtures/createOnce/plugin.ts | Updated test to destructure and use context.id in createOnce instead of testing that it throws an error |
| apps/oxlint/test/fixtures/createOnce/output.snap.md | Updated snapshots to show the expected rule ID value instead of the previous error message |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
#15447) Previously we blocked accessing `context.id` (rule name) in `createOnce`. There's no need to be so restrictive, as it's a static value, and not file-specific. Relax this restriction.
aecb99c to
981cbc5
Compare
…ce` (#15489) Revert #15447. It's easy to allow `Context#id` to be accessed in `createOnce` when running rule in Oxlint, but not possible to do in ESLint compat mode with current API, because `id` isn't a property of the rule, so `defineRule` doesn't know it. We could support it by making `definePlugin` compulsory for ESLint interop, and get it to set `id` property on `Context` objects properly. But that's a bit tricky, so just disable access for now. It's probably not very useful anyway - a rule should know what its own name is!

Previously we blocked accessing
context.id(rule name) increateOnce. There's no need to be so restrictive, as it's a static value, and not file-specific. Relax this restriction.