espree icon indicating copy to clipboard operation
espree copied to clipboard

Change Request: Remove `nodejsScope` option of eslint-scope

Open mdjermanovic opened this issue 4 months ago • 3 comments

Which packages would you like to change?

  • [ ] espree
  • [x] eslint-scope
  • [ ] eslint-visitor-keys

What problem do you want to solve?

Currently, there are two different ways to enable commonjs scope analysis:

  • sourceType: "commonjs"
  • nodejsScope: true

The effect is the same.

Furthermore, when the options are sourceType: "module" and nodejsScope: true, eslint-scope creates both the function scope (commonjs wrapper) and the module scope, which seems invalid.

import * as eslintScope from 'eslint-scope';
import * as espree from 'espree';

const code = "class C {}";

const options = {
    ecmaVersion: 2025,
    sourceType: "module",
    nodejsScope: true
};

const ast = espree.parse(code, { range: true, ...options });
const scopeManager = eslintScope.analyze(ast, options);

console.log(scopeManager.scopes.map(scope => scope.type)); // [ 'global', 'function', 'module', 'class' ]

What do you think is the correct solution?

Remove nodejsScope option as redundant for enabling commonjs scope analysis, and potentially problematic when used with sourceType: "module".

Participation

  • [x] I am willing to submit a pull request for this change.

Additional comments

No response

mdjermanovic avatar Oct 02 '25 16:10 mdjermanovic

👋 Hi! This issue is being addressed in pull request https://github.com/eslint/js/pull/699. Thanks, @mdjermanovic!

eslint-github-bot[bot] avatar Oct 09 '25 15:10 eslint-github-bot[bot]

The TSC unanimously agreed to remove nodejsScope from eslint-scope for v10.

sam3k avatar Oct 09 '25 20:10 sam3k

This has been postponed to ESLint v11, for the same reasons as https://github.com/eslint/js/issues/525.

mdjermanovic avatar Oct 25 '25 18:10 mdjermanovic