Skip to content

Commit

Permalink
normalize path segments to before doing comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Aug 12, 2016
1 parent f072e8a commit 275ddc8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/rules/no-reaching-inside.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ module.exports = function noReachingInside(context) {
const allowRegexps = (options.allow || []).map(p => minimatch.makeRe(p))

// test if reaching into this directory is allowed by the
// config, path.sep is automatically added so that globs like
// config, '/' is automatically added so that globs like
// "lodash/**" will match both "lodash" (which requires the trailing /) and "lodash/get"
function reachingAllowed(someDir) {
return !!find(allowRegexps, re => re.test(someDir) || re.test(someDir + path.sep))
return !!find(allowRegexps, re => re.test(someDir) || re.test(someDir + '/'))
}

function isRelativeStep (step) {
return step === '' || step === '.' || step === '..'
}

function normalizeSep(somePath) {
return somePath.split('\\').join('/')
}

function report(reachedTo, node) {
context.report({
node,
Expand All @@ -29,11 +33,11 @@ module.exports = function noReachingInside(context) {
}

function findNotAllowedReach(importPath, startingBase, join, ignoreStep) {
const steps = importPath.split('/').filter(Boolean)
const steps = normalizeSep(importPath).split('/').filter(Boolean)
let parentDir = startingBase
while (steps.length) {
const step = steps.shift()
parentDir = join(parentDir, step)
parentDir = normalizeSep(join(parentDir, step))

if (ignoreStep && ignoreStep(step)) continue

Expand Down

0 comments on commit 275ddc8

Please sign in to comment.