Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/oxlint/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,8 @@ describe('oxlint CLI', () => {
it('should support UTF16 characters in source code and comments with correct spans', async () => {
await testFixture('unicode-comments');
});

it('should report an error when a plugin wraps context and loses private #internal field', async () => {
await testFixture('oxc_issue_15325');
});
});
9 changes: 9 additions & 0 deletions apps/oxlint/test/fixtures/oxc_issue_15325/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"jsPlugins": ["./plugin.ts"],
"categories": {
"correctness": "off"
},
"rules": {
"wrapped-context/wrapped-rule": "error"
}
}
1 change: 1 addition & 0 deletions apps/oxlint/test/fixtures/oxc_issue_15325/files/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello, world!");
20 changes: 20 additions & 0 deletions apps/oxlint/test/fixtures/oxc_issue_15325/output.snap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Exit code
1

# stdout
```
x Error running JS plugin.
| File path: <root>/apps/oxlint/test/fixtures/oxc_issue_15325/files/index.js
| TypeError: Cannot read private member #internal from an object whose class did not declare it
| at Object.create (<root>/apps/oxlint/test/fixtures/oxc_issue_15325/plugin.ts:10:33)
| at Object.create (<root>/apps/oxlint/test/fixtures/oxc_issue_15325/plugin.ts:36:25)

Found 0 warnings and 1 error.
Finished in Xms on 1 file using X threads.
```

# stderr
```
WARNING: JS plugins are experimental and not subject to semver.
Breaking changes are possible while JS plugins support is under development.
```
42 changes: 42 additions & 0 deletions apps/oxlint/test/fixtures/oxc_issue_15325/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Plugin } from "../../../dist/index.js";

function trapReport(_context: any) {
return function (_obj: any) {};
}

const baseRule = {
create(context: any) {
// Base rule tries to access sourceCode
const _sourceCode = context.sourceCode;
return {
Identifier(node: any) {
context.report({
node,
message: "Base rule found identifier",
});
},
};
},
};

const plugin: Plugin = {
meta: {
name: "wrapped-context",
},
rules: {
"wrapped-rule": {
create(context) {
const contextForBaseRule = Object.create(context, {
report: {
value: trapReport(context),
writable: false,
},
});

return baseRule.create(contextForBaseRule);
},
},
},
};

export default plugin;
Loading