-
-
Notifications
You must be signed in to change notification settings - Fork 899
Description
What version of Oxlint are you using?
1.41.0
What command did you run?
npx oxlint --config oxlint.json
What does your .oxlintrc.json config file look like?
What happened?
Oxlint's JavaScript plugin API is documented to be fully compatible with ESLint v9+, including code path analysis. However, when using eslint-plugin-sonarjs via the JavaScript plugin API, code path listeners are sometimes called without the node parameter, or with null/undefined code path objects, causing errors.
Affected Rules
The following 7 rules from eslint-plugin-sonarjs are affected:
super-invocationno-parameter-reassignmentno-invariant-returnsno-inconsistent-returnsno-code-after-doneno-redundant-assignmentsno-dead-store
Issue Types
1. Missing Node Parameter in Code Path Listeners
Problem: Oxlint sometimes calls code path listeners without the node parameter that ESLint provides.
Expected behavior (per ESLint API):
onCodePathStart(codePath, node) // node should always be provided
onCodePathEnd(codePath, node)
onCodePathSegmentStart(segment, node)
onCodePathSegmentEnd(segment, node)
onCodePathSegmentLoop(fromSegment, toSegment, node)Actual behavior: These listeners are sometimes called with node as undefined or null.
Impact: Rules that expect a node parameter to call context.getScope(node) will fail with errors like:
TypeError: Missing required argument: 'node'Cannot read properties of undefined (reading 'type')
2. Null/Undefined Property Access Errors
Problem: Code path objects or nodes may be null/undefined when accessed by rule listeners.
Examples of errors observed:
Cannot read properties of null (reading 'isConstructor')- inCallExpression:exitandReturnStatementlistenersCannot read properties of null (reading 'hasExtends')- inonCodePathEndlistenerCannot read properties of null (reading 'currentSegments')- inonUnreachableCodePathSegmentStart/EndlistenersCannot read properties of undefined (reading 'type')- inonCodePathStartlistener
Impact: Rules that access properties on code path objects or nodes will throw errors instead of completing analysis.
3. Code Path Stack Not Initialized
Problem: Some rules access context.codePathStack or similar structures that may not be properly initialized in Oxlint.
Impact: Rules that rely on code path stack tracking will fail.
Current Workaround
We've implemented a workaround in our plugin wrapper that patches the affected rules to:
- Skip execution when node parameters are missing
- Catch and handle null/undefined property access errors
- Gracefully handle code path stack access errors
However, this workaround prevents crashes but may result in incomplete rule analysis for these rules.
Expected Behavior
According to the Oxlint JavaScript Plugin API documentation, the API should be "fully compatible with ESLint v9+", and code path listeners should receive both codePath and node parameters consistently, matching ESLint's behavior.
Minimal Reproduction
The issue can be reproduced directly with eslint-plugin-sonarjs (a JavaScript package, not TypeScript):
- Install
eslint-plugin-sonarjs:npm install eslint-plugin-sonarjs - Configure oxlint to use the plugin and enable any of the 7 affected rules
- Run oxlint on code that triggers code path analysis
The errors occur during normal linting when these rules attempt to analyze code paths.
Additional Context
- Documentation reference: ESLint Code Path Analysis
- Affected plugin: SonarJS Plugin
- This appears to be a compatibility gap in Oxlint's JavaScript plugin API implementation, not an issue with the ESLint plugin itself
- Note on API compatibility: While ESLint flat config requires
meta.namefor certain features (like--cacheand--print-config), some plugins may still function without it. Oxlint appears to strictly requiremeta.namefor all plugins, which is a minor API drift from ESLint's more lenient approach. However,eslint-plugin-sonarjsalready providesmeta.name, so this is not a factor in this particular issue.
{ "$schema": "./node_modules/oxlint/configuration_schema.json", "jsPlugins": [ "./plugins/sonarjs-plugin.js" ], "rules": { "sonarjs/super-invocation": "error", "sonarjs/no-parameter-reassignment": "error", "sonarjs/no-invariant-returns": "error", "sonarjs/no-inconsistent-returns": "error", "sonarjs/no-code-after-done": "error", "sonarjs/no-redundant-assignments": "error", "sonarjs/no-dead-store": "error" } }