test(linter): add failing test for wrapped eslint plugins#15326
test(linter): add failing test for wrapped eslint plugins#15326
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.
Pull Request Overview
This PR adds a test case to verify that oxlint properly handles and reports an error when a JavaScript plugin wraps the context object using Object.create(), which causes the loss of private internal fields. The test demonstrates that attempting to access properties from a wrapped context results in a TypeError.
- Adds a new test fixture
oxc_issue_15325that simulates a plugin wrapping the context object - Includes expected error output showing the TypeError when private members cannot be accessed
- Adds a corresponding test case in the e2e test suite
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| apps/oxlint/test/fixtures/oxc_issue_15325/plugin.ts | Creates a test plugin that wraps the context object using Object.create(), triggering the private field access error |
| apps/oxlint/test/fixtures/oxc_issue_15325/output.snap.md | Defines the expected error output snapshot showing the TypeError message |
| apps/oxlint/test/fixtures/oxc_issue_15325/files/index.js | Provides a simple test file to be linted by the plugin |
| apps/oxlint/test/fixtures/oxc_issue_15325/.oxlintrc.json | Configures the test to use the custom plugin with the wrapped-rule enabled |
| apps/oxlint/test/e2e.test.ts | Adds a test case to verify the error handling behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
These tests folded into #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.

adds a failing test for #15325