no-extraneous-import.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @author Toru Nagashima
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const { checkExtraneous, messages } = require("../util/check-extraneous")
  7. const getAllowModules = require("../util/get-allow-modules")
  8. const getConvertPath = require("../util/get-convert-path")
  9. const getResolvePaths = require("../util/get-resolve-paths")
  10. const visitImport = require("../util/visit-import")
  11. module.exports = {
  12. meta: {
  13. docs: {
  14. description:
  15. "disallow `import` declarations which import extraneous modules",
  16. category: "Possible Errors",
  17. recommended: true,
  18. url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-extraneous-import.md",
  19. },
  20. type: "problem",
  21. fixable: null,
  22. schema: [
  23. {
  24. type: "object",
  25. properties: {
  26. allowModules: getAllowModules.schema,
  27. convertPath: getConvertPath.schema,
  28. resolvePaths: getResolvePaths.schema,
  29. },
  30. additionalProperties: false,
  31. },
  32. ],
  33. messages,
  34. },
  35. create(context) {
  36. const filePath = context.getFilename()
  37. if (filePath === "<input>") {
  38. return {}
  39. }
  40. return visitImport(context, {}, targets => {
  41. checkExtraneous(context, filePath, targets)
  42. })
  43. },
  44. }