How to use the eslint-module-utils/resolve function in eslint-module-utils

To help you get started, we’ve selected a few eslint-module-utils 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 benmosher / eslint-plugin-import / src / rules / no-unused-modules.js View on Github external
node.body.forEach(astNode => {
        let resolvedPath

        // support for export { value } from 'module'
        if (astNode.type === EXPORT_NAMED_DECLARATION) {
          if (astNode.source) {
            resolvedPath = resolve(astNode.source.raw.replace(/('|")/g, ''), context)
            astNode.specifiers.forEach(specifier => {
              let name
              if (specifier.exported.name === DEFAULT) {
                name = IMPORT_DEFAULT_SPECIFIER
              } else {
                name = specifier.local.name
              }
              newImports.set(name, resolvedPath)
            })
          }
        }

        if (astNode.type === EXPORT_ALL_DECLARATION) {
          resolvedPath = resolve(astNode.source.raw.replace(/('|")/g, ''), context)
          newExportAll.add(resolvedPath)
        }
github benmosher / eslint-plugin-import / src / rules / no-internal-modules.js View on Github external
} else {
            return acc.concat(step)
          }
        }, [])

      const nonScopeSteps = steps.filter(step => step.indexOf('@') !== 0)
      if (nonScopeSteps.length <= 1) return false

      // before trying to resolve, see if the raw import (with relative
      // segments resolved) matches an allowed pattern
      const justSteps = steps.join('/')
      if (reachingAllowed(justSteps) || reachingAllowed(`/${justSteps}`)) return false

      // if the import statement doesn't match directly, try to match the
      // resolved path if the import is resolvable
      const resolved = resolve(importPath, context)
      if (!resolved || reachingAllowed(normalizeSep(resolved))) return false

      // this import was not allowed by the allowed paths, and reaches
      // so it is a violation
      return true
    }
github benmosher / eslint-plugin-import / tests / src / core / resolve.js View on Github external
it('gets correct values after cache lifetime', function () {
            expect(resolve(original, context)).not.to.exist
            expect(resolve(changed, context)).to.exist
          })
        })
github benmosher / eslint-plugin-import / tests / src / core / resolve.js View on Github external
it('resolves via a custom resolver with interface version 1 assumed if not specified', function () {
    const testContext = utils.testContext({ 'import/resolver': './foo-bar-resolver-no-version' })

    expect(resolve( '../files/foo'
                      , Object.assign({}, testContext, { getFilename: function () { return utils.getFilename('foo.js') } }),
                      )).to.equal(utils.testFilePath('./bar.jsx'))

    expect(resolve( '../files/exception'
                      , Object.assign({}, testContext, { getFilename: function () { return utils.getFilename('exception.js') } }),
                    )).to.equal(undefined)

    expect(resolve( '../files/not-found'
                      , Object.assign({}, testContext, { getFilename: function () { return utils.getFilename('not-found.js') } }),
                    )).to.equal(undefined)
  })
github benmosher / eslint-plugin-import / tests / src / core / resolve.js View on Github external
it('respects import/resolve extensions', function () {
    const testContext = utils.testContext({ 'import/resolve': { 'extensions': ['.jsx'] }})

    expect(resolve( './jsx/MyCoolComponent'
                      , testContext,
                      )).to.equal(utils.testFilePath('./jsx/MyCoolComponent.jsx'))
  })
github benmosher / eslint-plugin-import / tests / src / core / resolve.js View on Github external
infiniteContexts.forEach(([,c]) => {
            expect(resolve(original, c)).to.exist
          })
        })
github benmosher / eslint-plugin-import / src / core / importType.js View on Github external
export default function resolveImportType(name, context) {
  return typeTest(name, context.settings, resolve(name, context))
}
github benmosher / eslint-plugin-import / src / rules / no-duplicates.js View on Github external
    const defaultResolver = sourcePath => resolve(sourcePath, context) || sourcePath
    const resolver = considerQueryStringOption ? (sourcePath => {
github benmosher / eslint-plugin-import / src / rules / extensions.js View on Github external
function isResolvableWithoutExtension(file) {
      const extension = path.extname(file)
      const fileWithoutExtension = file.slice(0, -extension.length)
      const resolvedFileWithoutExtension = resolve(fileWithoutExtension, context)

      return resolvedFileWithoutExtension === resolve(file, context)
    }
github benmosher / eslint-plugin-import / src / rules / no-restricted-paths.js View on Github external
function checkForRestrictedImportPath(importPath, node) {
        const absoluteImportPath = resolve(importPath, context)

        if (!absoluteImportPath) {
          return
        }

        matchingZones.forEach((zone) => {
          const absoluteFrom = path.resolve(basePath, zone.from)

          if (containsPath(absoluteImportPath, absoluteFrom)) {
            context.report({
              node,
              message: `Unexpected path "${importPath}" imported in restricted zone.`,
            })
          }
        })
    }