How to use eslint-plugin-import - 4 common examples

To help you get started, we’ve selected a few eslint-plugin-import examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github silklabs / silk / eslint-plugin / no-extraneous-dependencies.js View on Github external
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') ||
github instructure / instructure-ui / packages / eslint-plugin-instructure-ui / lib / rules / no-relative-package-imports.js View on Github external
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)
github michalkvasnicak / create-js-app / packages / eslint-config-js-app / index.js View on Github external
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',
github silklabs / silk / eslint-plugin / no-extraneous-dependencies.js View on Github external
CallExpression: function handleRequires(node) {
        if (isStaticRequire(node)) {
          reportIfMissing(context, pkg, depsOptions, node, node.arguments[0].value);
        }
      },
    };