Skip to content

test(linter): add failing test for wrapped eslint plugins#15326

Closed
camc314 wants to merge 1 commit intomainfrom
c/11-05-test_linter_add_failing_test_for_wrapped_eslint_plugins
Closed

test(linter): add failing test for wrapped eslint plugins#15326
camc314 wants to merge 1 commit intomainfrom
c/11-05-test_linter_add_failing_test_for_wrapped_eslint_plugins

Conversation

@camc314
Copy link
Contributor

@camc314 camc314 commented Nov 5, 2025

adds a failing test for #15325

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI C-test Category - Testing. Code is missing test cases, or a PR is adding them labels Nov 5, 2025
Copy link
Contributor Author

camc314 commented Nov 5, 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.

@camc314 camc314 marked this pull request as ready for review November 5, 2025 13:07
Copilot AI review requested due to automatic review settings November 5, 2025 13:07
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 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_15325 that 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.

@overlookmotel
Copy link
Member

These tests folded into #15448.

@overlookmotel overlookmotel deleted the c/11-05-test_linter_add_failing_test_for_wrapped_eslint_plugins branch November 7, 2025 19:44
graphite-app bot pushed a commit that referenced this pull request Nov 7, 2025
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.
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-test Category - Testing. Code is missing test cases, or a PR is adding them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants