Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
while (untraversed.length > 0) {
const next = untraversed.shift() // bfs!
if (detectCycle(next)) {
const message = (next.route.length > 0
? `Dependency cycle via ${routeString(next.route)}`
: 'Dependency cycle detected.')
context.report(importer, message)
return
}
}
}
return moduleVisitor(checkSourceValue, context.options[0])
},
}
create: function (context) {
function reportIfAbsolute(source) {
if (isAbsolute(source.value)) {
context.report(source, 'Do not import modules using an absolute path')
}
}
const options = Object.assign({ esmodule: true, commonjs: true }, context.options[0])
return moduleVisitor(reportIfAbsolute, options)
},
}
const expectedNRelParents = countRelParent(expectedSplit)
const diff = valueNRelParents - expectedNRelParents
if (diff <= 0) {
return
}
return report(
toRel(valueSplit
.slice(0, expectedNRelParents)
.concat(valueSplit.slice(valueNRelParents + diff))
.join('/'))
)
}
return moduleVisitor(checkSourceValue, context.options[0])
},
}
}
const relDepPath = relative(dirname(myPath), absDepPath)
if (importType(relDepPath, context) === 'parent') {
context.report({
node: sourceNode,
message: 'Relative imports from parent directories are not allowed. ' +
`Please either pass what you're importing through at runtime ` +
`(dependency injection), move \`${basename(myPath)}\` to same ` +
`directory as \`${depPath}\` or consider making \`${depPath}\` a package.`,
})
}
}
return moduleVisitor(checkSourceValue, context.options[0])
},
}
if (resolvedPath === undefined) {
context.report(source,
`Unable to resolve path to module '${source.value}'.`)
}
else if (shouldCheckCase) {
const cacheSettings = ModuleCache.getSettings(context.settings)
if (!fileExistsWithCaseSync(resolvedPath, cacheSettings)) {
context.report(source,
`Casing of ${source.value} does not match the underlying filesystem.`)
}
}
}
return moduleVisitor(checkSourceValue, context.options[0])
},
}