no-missing-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 checkExistence = require("../util/check-existence")
  7. const getAllowModules = require("../util/get-allow-modules")
  8. const getResolvePaths = require("../util/get-resolve-paths")
  9. const getTryExtensions = require("../util/get-try-extensions")
  10. const visitImport = require("../util/visit-import")
  11. module.exports = {
  12. meta: {
  13. docs: {
  14. description:
  15. "disallow `import` declarations which import non-existence modules",
  16. category: "Possible Errors",
  17. recommended: true,
  18. url:
  19. "https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-missing-import.md",
  20. },
  21. type: "problem",
  22. fixable: null,
  23. schema: [
  24. {
  25. type: "object",
  26. properties: {
  27. allowModules: getAllowModules.schema,
  28. tryExtensions: getTryExtensions.schema,
  29. resolvePaths: getResolvePaths.schema,
  30. },
  31. additionalProperties: false,
  32. },
  33. ],
  34. },
  35. create(context) {
  36. const filePath = context.getFilename()
  37. if (filePath === "<input>") {
  38. return {}
  39. }
  40. return visitImport(context, {}, targets => {
  41. checkExistence(context, targets)
  42. })
  43. },
  44. }