@@ -14,7 +14,7 @@ module.exports = function noReachingInside(context) {
14
14
return ! ! find ( allowRegexps , re => re . test ( importPath ) )
15
15
}
16
16
17
- // minimatch patterns are expected to use / path seperators , like import
17
+ // minimatch patterns are expected to use / path separators , like import
18
18
// statements, so normalize paths to use the same
19
19
function normalizeSep ( somePath ) {
20
20
return somePath . split ( '\\' ) . join ( '/' )
@@ -39,35 +39,27 @@ module.exports = function noReachingInside(context) {
39
39
// before trying to resolve, see if the raw import (with relative
40
40
// segments resolved) matches an allowed pattern
41
41
const justSteps = steps . join ( '/' )
42
- if ( reachingAllowed ( justSteps ) ) return false
43
- if ( reachingAllowed ( `/${ justSteps } ` ) ) return false
42
+ if ( reachingAllowed ( justSteps ) || reachingAllowed ( `/${ justSteps } ` ) ) return false
44
43
45
44
// if the import statement doesn't match directly, try to match the
46
45
// resolved path if the import is resolvable
47
46
const resolved = resolve ( importPath , context )
48
- if ( ! resolved ) return false
49
- if ( reachingAllowed ( normalizeSep ( resolved ) ) ) return false
47
+ if ( ! resolved || reachingAllowed ( normalizeSep ( resolved ) ) ) return false
50
48
51
49
// this import was not allowed by the allowed paths, and reaches
52
50
// so it is a violation
53
51
return true
54
52
}
55
53
56
54
function checkImportForReaching ( importPath , node ) {
57
- switch ( importType ( importPath , context ) ) {
58
- case 'parent' :
59
- case 'index' :
60
- case 'sibling' :
61
- case 'external' :
62
- case 'internal' : {
63
- if ( isReachViolation ( importPath ) ) {
64
- context . report ( {
65
- node,
66
- message : `Reaching to "${ importPath } " is not allowed.` ,
67
- } )
68
- }
69
- break
70
- }
55
+ const potentialViolationTypes = [ 'parent' , 'index' , 'sibling' , 'external' , 'internal' ]
56
+ if ( potentialViolationTypes . indexOf ( importType ( importPath , context ) ) !== - 1 &&
57
+ isReachViolation ( importPath )
58
+ ) {
59
+ context . report ( {
60
+ node,
61
+ message : `Reaching to "${ importPath } " is not allowed.` ,
62
+ } )
71
63
}
72
64
}
73
65
0 commit comments