Which packages would you like to change?
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
Additional comments
No response
Which packages would you like to change?
espreeeslint-scopeeslint-visitor-keysWhat problem do you want to solve?
Currently, there are two different ways to enable commonjs scope analysis:
sourceType: "commonjs"nodejsScope: trueThe effect is the same.
Furthermore, when the options are
sourceType: "module"andnodejsScope: true, eslint-scope creates both thefunctionscope (commonjs wrapper) and themodulescope, which seems invalid.What do you think is the correct solution?
Remove
nodejsScopeoption as redundant for enabling commonjs scope analysis, and potentially problematic when used withsourceType: "module".Participation
Additional comments
No response