Skip to content

Commit 0509d70

Browse files
author
spalger
committed
code style improvements
1 parent d0ce3a8 commit 0509d70

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/rules/no-reaching-inside.js

+11-19
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = function noReachingInside(context) {
1414
return !!find(allowRegexps, re => re.test(importPath))
1515
}
1616

17-
// minimatch patterns are expected to use / path seperators, like import
17+
// minimatch patterns are expected to use / path separators, like import
1818
// statements, so normalize paths to use the same
1919
function normalizeSep(somePath) {
2020
return somePath.split('\\').join('/')
@@ -39,35 +39,27 @@ module.exports = function noReachingInside(context) {
3939
// before trying to resolve, see if the raw import (with relative
4040
// segments resolved) matches an allowed pattern
4141
const justSteps = steps.join('/')
42-
if (reachingAllowed(justSteps)) return false
43-
if (reachingAllowed(`/${justSteps}`)) return false
42+
if (reachingAllowed(justSteps) || reachingAllowed(`/${justSteps}`)) return false
4443

4544
// if the import statement doesn't match directly, try to match the
4645
// resolved path if the import is resolvable
4746
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
5048

5149
// this import was not allowed by the allowed paths, and reaches
5250
// so it is a violation
5351
return true
5452
}
5553

5654
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+
})
7163
}
7264
}
7365

0 commit comments

Comments
 (0)