Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function reportIfMissing(context, pkg, depsOptions, node, name) {
if (importType(name, context) !== 'external') {
return;
}
const splitName = name.split('/');
const packageName = splitName[0][0] === '@'
? splitName.slice(0, 2).join('/')
: splitName[0];
const isSelf = packageName === pkg.pkg.name;
const inWhichDeps = findPackageInDependencies(packageName, pkg.pkg);
const deps = getDependencies(pkg.pkg);
const isInDeps = deps.dependencies[packageName] !== undefined;
if (isInDeps ||
(depsOptions.allowSelf && isSelf) ||
(depsOptions.allowDevDeps && inWhichDeps === 'devDependencies') ||
(depsOptions.allowPeerDeps && inWhichDeps === 'peerDependencies') ||
function checkImportForRelativePackage (importPath, node) {
const potentialViolationTypes = ['parent', 'index', 'sibling']
if (potentialViolationTypes.indexOf(resolveImportType(importPath, context)) === -1) {
return
}
const resolvedImport = resolve(importPath, context)
const resolvedContext = context.getFilename()
if (!resolvedImport || !resolvedContext) {
return
}
const importPkg = findNamedPackage(resolvedImport)
const contextPkg = findNamedPackage(resolvedContext)
if (importPkg.package && contextPkg.package && importPkg.package.name !== contextPkg.package.name) {
const importBaseName = path.basename(importPath)
const importRoot = path.dirname(importPkg.path)
const importPluginRules = Object.keys(require('eslint-plugin-import').rules);
const airbnbConfig = Object.assign(
{},
require('eslint-config-airbnb'),
{
root: true,
env: {
browser: true,
commonjs: true,
es6: true,
jest: true,
node: true,
},
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 8,
sourceType: 'module',
CallExpression: function handleRequires(node) {
if (isStaticRequire(node)) {
reportIfMissing(context, pkg, depsOptions, node, node.arguments[0].value);
}
},
};