File tree 6 files changed +16
-10
lines changed
6 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import isStaticRequire from '../core/staticRequire';
7
7
import docsUrl from '../docsUrl' ;
8
8
9
9
import debug from 'debug' ;
10
- import { getFilename } from '../context' ;
10
+ import { getFilename , getScope } from '../context' ;
11
11
const log = debug ( 'eslint-plugin-import:rules:newline-after-import' ) ;
12
12
13
13
//------------------------------------------------------------------------------
@@ -195,10 +195,12 @@ module.exports = {
195
195
} ,
196
196
'Program:exit' ( ) {
197
197
log ( 'exit processing for' , context . getPhysicalFilename ? context . getPhysicalFilename ( ) : getFilename ( context ) ) ;
198
- const scopeBody = getScopeBody ( context . getScope ( ) ) ;
199
- log ( 'got scope:' , scopeBody ) ;
200
198
201
199
requireCalls . forEach ( ( node , index ) => {
200
+ // todo: this probably isn't correct...
201
+ const scopeBody = getScopeBody ( getScope ( context , node ) ) ;
202
+ log ( 'got scope:' , scopeBody ) ;
203
+
202
204
const nodePosition = findNodeIndexInScopeBody ( scopeBody , node ) ;
203
205
log ( 'node position in scope:' , nodePosition ) ;
204
206
Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
import docsUrl from '../docsUrl' ;
7
+ import { getScope } from '../context' ;
7
8
8
9
//------------------------------------------------------------------------------
9
10
// Rule Definition
@@ -23,7 +24,7 @@ module.exports = {
23
24
create ( context ) {
24
25
return {
25
26
CallExpression ( node ) {
26
- if ( context . getScope ( ) . type !== 'module' ) { return ; }
27
+ if ( getScope ( context , node ) . type !== 'module' ) { return ; }
27
28
28
29
if ( node . callee . type !== 'Identifier' ) { return ; }
29
30
if ( node . callee . name !== 'require' && node . callee . name !== 'define' ) { return ; }
Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
import docsUrl from '../docsUrl' ;
7
+ import { getScope } from '../context' ;
7
8
8
9
const EXPORT_MESSAGE = 'Expected "export" or "export default"' ;
9
10
const IMPORT_MESSAGE = 'Expected "import" instead of "require()"' ;
@@ -107,7 +108,7 @@ module.exports = {
107
108
108
109
// exports.
109
110
if ( node . object . name === 'exports' ) {
110
- const isInScope = context . getScope ( )
111
+ const isInScope = getScope ( context , node )
111
112
. variables
112
113
. some ( ( variable ) => variable . name === 'exports' ) ;
113
114
if ( ! isInScope ) {
@@ -117,7 +118,7 @@ module.exports = {
117
118
118
119
} ,
119
120
CallExpression ( call ) {
120
- if ( ! validateScope ( context . getScope ( ) ) ) { return ; }
121
+ if ( ! validateScope ( getScope ( context , call ) ) ) { return ; }
121
122
122
123
if ( call . callee . type !== 'Identifier' ) { return ; }
123
124
if ( call . callee . name !== 'require' ) { return ; }
Original file line number Diff line number Diff line change 1
1
import docsUrl from '../docsUrl' ;
2
+ import { getScope } from '../context' ;
2
3
3
4
module . exports = {
4
5
meta : {
@@ -32,15 +33,15 @@ module.exports = {
32
33
}
33
34
34
35
function handleExportDefault ( node ) {
35
- const scope = context . getScope ( ) ;
36
+ const scope = getScope ( context , node ) ;
36
37
37
38
if ( node . declaration . name ) {
38
39
checkDeclarationsInScope ( scope , node . declaration . name ) ;
39
40
}
40
41
}
41
42
42
43
function handleExportNamed ( node ) {
43
- const scope = context . getScope ( ) ;
44
+ const scope = getScope ( context , node ) ;
44
45
45
46
if ( node . declaration ) {
46
47
checkDeclaration ( node . declaration ) ;
Original file line number Diff line number Diff line change 5
5
6
6
import minimatch from 'minimatch' ;
7
7
import docsUrl from '../docsUrl' ;
8
- import { getSourceCode } from '../context' ;
8
+ import { getScope , getSourceCode } from '../context' ;
9
9
10
10
/**
11
11
* @param {MemberExpression } memberExpression
@@ -109,7 +109,7 @@ module.exports = {
109
109
return ;
110
110
}
111
111
112
- const scopeVariables = context . getScope ( ) . variables ;
112
+ const scopeVariables = getScope ( context , node ) . variables ;
113
113
const namespaceVariable = scopeVariables . find ( ( variable ) => variable . defs [ 0 ] . node === node ) ;
114
114
const namespaceReferences = namespaceVariable . references ;
115
115
const namespaceIdentifiers = namespaceReferences . map ( ( reference ) => reference . identifier ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ exports.__esModule = true;
4
4
5
5
/** @type {import('./declaredScope').default } */
6
6
exports . default = function declaredScope ( context , name ) {
7
+ // todo: what should be done about this...
7
8
const references = context . getScope ( ) . references ;
8
9
const reference = references . find ( ( x ) => x . identifier . name === name ) ;
9
10
if ( ! reference || ! reference . resolved ) { return undefined ; }
You can’t perform that action at this time.
0 commit comments