@@ -258,7 +258,7 @@ module.exports = {
258258 const batchAssignAllowed = Boolean (
259259 context . options [ 1 ] != null && context . options [ 1 ] . allowBatchAssign
260260 )
261- const sourceCode = context . getSourceCode ( )
261+ const sourceCode = context . sourceCode ?? context . getSourceCode ( ) // TODO: just use context.sourceCode when dropping eslint < v9
262262
263263 /**
264264 * Gets the location info of reports.
@@ -286,8 +286,7 @@ module.exports = {
286286 *
287287 * @returns {void }
288288 */
289- function enforceModuleExports ( ) {
290- const globalScope = context . getScope ( )
289+ function enforceModuleExports ( globalScope ) {
291290 const exportsNodes = getExportsNodes ( globalScope )
292291 const assignList = batchAssignAllowed
293292 ? createAssignmentList ( getModuleExportsNodes ( globalScope ) )
@@ -317,8 +316,7 @@ module.exports = {
317316 *
318317 * @returns {void }
319318 */
320- function enforceExports ( ) {
321- const globalScope = context . getScope ( )
319+ function enforceExports ( globalScope ) {
322320 const exportsNodes = getExportsNodes ( globalScope )
323321 const moduleExportsNodes = getModuleExportsNodes ( globalScope )
324322 const assignList = batchAssignAllowed
@@ -370,13 +368,15 @@ module.exports = {
370368 }
371369
372370 return {
373- "Program:exit" ( ) {
371+ "Program:exit" ( node ) {
372+ const scope = sourceCode . getScope ?. ( node ) ?? context . getScope ( ) //TODO: remove context.getScope() when dropping support for ESLint < v9
373+
374374 switch ( mode ) {
375375 case "module.exports" :
376- enforceModuleExports ( )
376+ enforceModuleExports ( scope )
377377 break
378378 case "exports" :
379- enforceExports ( )
379+ enforceExports ( scope )
380380 break
381381
382382 // no default
0 commit comments