@@ -258,7 +258,7 @@ module.exports = {
258
258
const batchAssignAllowed = Boolean (
259
259
context . options [ 1 ] != null && context . options [ 1 ] . allowBatchAssign
260
260
)
261
- const sourceCode = context . getSourceCode ( )
261
+ const sourceCode = context . sourceCode ?? context . getSourceCode ( ) // TODO: just use context.sourceCode when dropping eslint < v9
262
262
263
263
/**
264
264
* Gets the location info of reports.
@@ -286,8 +286,7 @@ module.exports = {
286
286
*
287
287
* @returns {void }
288
288
*/
289
- function enforceModuleExports ( ) {
290
- const globalScope = context . getScope ( )
289
+ function enforceModuleExports ( globalScope ) {
291
290
const exportsNodes = getExportsNodes ( globalScope )
292
291
const assignList = batchAssignAllowed
293
292
? createAssignmentList ( getModuleExportsNodes ( globalScope ) )
@@ -317,8 +316,7 @@ module.exports = {
317
316
*
318
317
* @returns {void }
319
318
*/
320
- function enforceExports ( ) {
321
- const globalScope = context . getScope ( )
319
+ function enforceExports ( globalScope ) {
322
320
const exportsNodes = getExportsNodes ( globalScope )
323
321
const moduleExportsNodes = getModuleExportsNodes ( globalScope )
324
322
const assignList = batchAssignAllowed
@@ -370,13 +368,15 @@ module.exports = {
370
368
}
371
369
372
370
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
+
374
374
switch ( mode ) {
375
375
case "module.exports" :
376
- enforceModuleExports ( )
376
+ enforceModuleExports ( scope )
377
377
break
378
378
case "exports" :
379
- enforceExports ( )
379
+ enforceExports ( scope )
380
380
break
381
381
382
382
// no default
0 commit comments