Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Nov 7, 2025

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.

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Nov 7, 2025
Copy link
Member Author

overlookmotel commented Nov 7, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@overlookmotel overlookmotel marked this pull request as ready for review November 7, 2025 19:19
Copilot AI review requested due to automatic review settings November 7, 2025 19:19
Copy link
Contributor

Copilot AI left a 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 id getter in the Context class to bypass the getInternal validation check
  • Updated test fixtures to verify that context.id is now accessible in createOnce
  • 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.

@overlookmotel overlookmotel self-assigned this Nov 7, 2025
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Nov 7, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 7, 2025

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.
@graphite-app graphite-app bot force-pushed the 11-07-refactor_linter_plugins_allow_accessing_context.id_in_createonce_ branch from aecb99c to 981cbc5 Compare November 7, 2025 19:44
@graphite-app graphite-app bot merged commit 981cbc5 into main Nov 7, 2025
18 checks passed
@graphite-app graphite-app bot deleted the 11-07-refactor_linter_plugins_allow_accessing_context.id_in_createonce_ branch November 7, 2025 19:49
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 7, 2025
graphite-app bot pushed a commit that referenced this pull request Nov 8, 2025
…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!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants