Skip to content

linter: JavaScript plugin code path listeners missing node parameter #18555

@C5G6M7

Description

@C5G6M7

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?

{
  "$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"
  }
}

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:

  1. super-invocation
  2. no-parameter-reassignment
  3. no-invariant-returns
  4. no-inconsistent-returns
  5. no-code-after-done
  6. no-redundant-assignments
  7. no-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') - in CallExpression:exit and ReturnStatement listeners
  • Cannot read properties of null (reading 'hasExtends') - in onCodePathEnd listener
  • Cannot read properties of null (reading 'currentSegments') - in onUnreachableCodePathSegmentStart/End listeners
  • Cannot read properties of undefined (reading 'type') - in onCodePathStart listener

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):

  1. Install eslint-plugin-sonarjs: npm install eslint-plugin-sonarjs
  2. Configure oxlint to use the plugin and enable any of the 7 affected rules
  3. 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.name for certain features (like --cache and --print-config), some plugins may still function without it. Oxlint appears to strictly require meta.name for all plugins, which is a minor API drift from ESLint's more lenient approach. However, eslint-plugin-sonarjs already provides meta.name, so this is not a factor in this particular issue.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions