How to use the eslint-module-utils/moduleVisitor 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-cycle.js View on Github external
}
      }

      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])
  },
}
github benmosher / eslint-plugin-import / src / rules / no-absolute-path.js View on Github external
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)
  },
}
github benmosher / eslint-plugin-import / src / rules / no-useless-path-segments.js View on Github external
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])
  },
}
github benmosher / eslint-plugin-import / src / rules / no-relative-parent-imports.js View on Github external
}

      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])
  },
}
github benmosher / eslint-plugin-import / src / rules / no-unresolved.js View on Github external
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])

  },
}