Skip to content

Commit a17ca32

Browse files
committed
fix(linter/plugins): replace Context class (#15448)
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.
1 parent 981cbc5 commit a17ca32

File tree

11 files changed

+423
-193
lines changed

11 files changed

+423
-193
lines changed

apps/oxlint/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"execa": "^9.6.0",
4545
"jiti": "^2.6.0",
4646
"tsdown": "catalog:",
47+
"type-fest": "^5.2.0",
4748
"typescript": "catalog:",
4849
"vitest": "catalog:"
4950
},

0 commit comments

Comments
 (0)