How to use the eslint-module-utils/resolve.default 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 Tibfib / eslint-plugin-import-helpers / src / util / import-type.js View on Github external
function resolveImportType(name, context, regExpGroups) {
	let matchingRegExpGroup = regExpGroups.find(([_groupName, regExp]) => regExp.test(name));
	if (matchingRegExpGroup) {
		return matchingRegExpGroup[0];
	}

	return typeTest(name, context.settings, resolve(name, context));
}
github github / eslint-plugin-github / lib / rules / dependency-graph.js View on Github external
ImportDeclaration(node) {
        const resolvedPath = resolve(node.source.value, context)
        if (!resolvedPath) {
          return
        }

        recordImport(resolvedPath)

        node.specifiers.forEach(specifier => {
          if (specifier.type === 'ImportDefaultSpecifier') {
            recordImport(resolvedPath, DEFAULT)
          } else if (specifier.type === 'ImportSpecifier') {
            recordImport(resolvedPath, specifier.imported.name)
          }
        })
      },
      ExportDefaultDeclaration() {
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)
        const properPath = path.relative(importRoot, resolvedImport)
        const properImport = path.join(
          importPkg.package.name,
          path.dirname(properPath),
github elastic / kibana / packages / kbn-eslint-plugin-eslint / rules / no_restricted_paths.js View on Github external
function checkForRestrictedImportPath(importPath, node) {
      const absoluteImportPath = importPath[0] === '.' ? resolve(importPath, context) : undefined;

      const currentFilename = context.getFilename();
      for (const { target, from, allowSameFolder, errorMessage = '' } of zones) {
        const srcFilePath = resolve(currentFilename, context);

        const relativeSrcFile = path.relative(basePath, srcFilePath);
        const relativeImportFile = absoluteImportPath
          ? path.relative(basePath, absoluteImportPath)
          : importPath;

        if (
          !mm([relativeSrcFile], target).length ||
          !mm([relativeImportFile], from).length ||
          (allowSameFolder && isSameFolderOrDescendent(relativeSrcFile, relativeImportFile, from))
        )
          continue;

        context.report({
          node,
          message: `Unexpected path "${importPath}" imported in restricted zone.${
github github / eslint-plugin-github / lib / rules / dependency-graph.js View on Github external
CallExpression(node) {
        if (node.callee.type === 'Identifier' && node.callee.name === 'require' && node.arguments.length === 1) {
          const pathNode = node.arguments[0]
          if (pathNode.type === 'Literal' && typeof pathNode.value === 'string') {
            const resolvedPath =
              pathNode.type === 'Literal' && typeof pathNode.value === 'string' && resolve(pathNode.value, context)

            if (resolvedPath) {
              recordImport(resolvedPath, STAR)
            }
          }
        }
      },
      MemberExpression(node) {
github elastic / kibana / packages / kbn-eslint-plugin-eslint / rules / no_restricted_paths.js View on Github external
function checkForRestrictedImportPath(importPath, node) {
      const absoluteImportPath = importPath[0] === '.' ? resolve(importPath, context) : undefined;

      const currentFilename = context.getFilename();
      for (const { target, from, allowSameFolder, errorMessage = '' } of zones) {
        const srcFilePath = resolve(currentFilename, context);

        const relativeSrcFile = path.relative(basePath, srcFilePath);
        const relativeImportFile = absoluteImportPath
          ? path.relative(basePath, absoluteImportPath)
          : importPath;

        if (
          !mm([relativeSrcFile], target).length ||
          !mm([relativeImportFile], from).length ||
          (allowSameFolder && isSameFolderOrDescendent(relativeSrcFile, relativeImportFile, from))
        )
          continue;
github janpaul123 / eslint-plugin-import-order-alphabetical / importType.js View on Github external
function resolveImportType(name, context) {
  return typeTest(name, context.settings, resolve(name, context))
}