no-extraneous-import.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @author Toru Nagashima
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const checkExtraneous = require("../util/check-extraneous")
  7. const getAllowModules = require("../util/get-allow-modules")
  8. const getConvertPath = require("../util/get-convert-path")
  9. const getImportTargets = require("../util/get-import-export-targets")
  10. const getResolvePaths = require("../util/get-resolve-paths")
  11. module.exports = {
  12. meta: {
  13. docs: {
  14. description:
  15. "disallow `import` declarations of extraneous packages",
  16. category: "Possible Errors",
  17. recommended: false,
  18. url:
  19. "https://github.com/mysticatea/eslint-plugin-node/blob/v8.0.1/docs/rules/no-extraneous-import.md",
  20. },
  21. type: "problem",
  22. fixable: null,
  23. schema: [
  24. {
  25. type: "object",
  26. properties: {
  27. allowModules: getAllowModules.schema,
  28. convertPath: getConvertPath.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 {
  41. "Program:exit"(node) {
  42. checkExtraneous(
  43. context,
  44. filePath,
  45. getImportTargets(context, node, false)
  46. )
  47. },
  48. }
  49. },
  50. }