33
44'use strict'
55
6- const { getScope } = require ( './lib/eslint-compat' )
6+ const { getSourceCode } = require ( './lib/eslint-compat' )
77const getDocsUrl = require ( './lib/get-docs-url' )
88
99function isDeclared ( scope , ref ) {
@@ -46,22 +46,24 @@ module.exports = {
4646 * @private
4747 */
4848 return {
49- 'Program:exit' ( node ) {
50- const scope = getScope ( context , node )
51- const leftToBeResolved =
52- scope . implicit . left ||
53- /**
54- * Fixes https://github.com/eslint-community/eslint-plugin-promise/issues/205.
55- * The problem was that @typescript-eslint has a scope manager
56- * which has `leftToBeResolved` instead of the default `left`.
57- */
58- scope . implicit . leftToBeResolved
49+ 'Program:exit' ( ) {
50+ const sourceCode = getSourceCode ( context )
51+ /** @type {import('eslint').Scope.Scope } */
52+ const scope = sourceCode . scopeManager . globalScope
5953
60- leftToBeResolved . forEach ( ( ref ) => {
54+ for ( const variable of scope . variables ) {
55+ if ( variable . name !== 'Promise' ) {
56+ continue
57+ }
58+ variable . references . forEach ( validatePromiseReference )
59+ }
60+ for ( const ref of scope . through ) {
6161 if ( ref . identifier . name !== 'Promise' ) {
62- return
62+ continue
6363 }
64-
64+ validatePromiseReference ( ref )
65+ }
66+ function validatePromiseReference ( ref ) {
6567 // istanbul ignore else
6668 if ( ! isDeclared ( scope , ref ) ) {
6769 context . report ( {
@@ -70,7 +72,7 @@ module.exports = {
7072 data : { name : ref . identifier . name } ,
7173 } )
7274 }
73- } )
75+ }
7476 } ,
7577 }
7678 } ,
0 commit comments