fix(linter/plugins): replace Context class#15448
Merged
graphite-app[bot] merged 1 commit intomainfrom Nov 7, 2025
Merged
Conversation
Member
Author
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. |
80df3ec to
34fa651
Compare
Contributor
Merge activity
|
Fix #15325. Some ESLint rules create a wrapped copy of `context`, in order to patch `report` and pass that wrapped context object to another rule. Some rules also rely on unspecified details of ESLint's implementation - that `context` is formed of 2 layers - top layer being `RuleContext` (`id`, `report` etc), and bottom layer being `FileContext` (`filename`, `sourceText` etc). This usage was broken in our implementation because: 1. We collapsed the 2 layers into 1. 2. We used a `Context` class which stored its internal data in a private property. When `context.report` was called with a different `this`, it failed because the private property couldn't be accessed from an object which isn't an instance of the class. Fix this problem by: 1. Splitting `Context` into 2 layers like ESLint does. 2. Not using classes or private properties. 3. No methods/getters on context objects use `this`. We now have: * Separate `Context` object per rule, containing properties related to the rule - a plain object which uses data from closure scope. * All rule `Context`s inherit from the same singleton `FILE_CONTEXT` object, which provides getters for properties related to the file (same for all rules). Tests adapted from #15326.
aecb99c to
981cbc5
Compare
34fa651 to
a17ca32
Compare
Base automatically changed from
11-07-refactor_linter_plugins_allow_accessing_context.id_in_createonce_
to
main
November 7, 2025 19:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fix #15325.
Some ESLint rules create a wrapped copy of
context, in order to patchreportand pass that wrapped context object to another rule.Some rules also rely on unspecified details of ESLint's implementation - that
contextis formed of 2 layers - top layer beingRuleContext(id,reportetc), and bottom layer beingFileContext(filename,sourceTextetc).This usage was broken in our implementation because:
Contextclass which stored its internal data in a private property. Whencontext.reportwas called with a differentthis, it failed because the private property couldn't be accessed from an object which isn't an instance of the class.Fix this problem by:
Contextinto 2 layers like ESLint does.this.We now have:
Contextobject per rule, containing properties related to the rule - a plain object which uses data from closure scope.Contexts inherit from the same singletonFILE_CONTEXTobject, which provides getters for properties related to the file (same for all rules).Tests adapted from #15326.