no-unpublished-import.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @author Toru Nagashima
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const checkPublish = require("../util/check-publish")
  7. const getAllowModules = require("../util/get-allow-modules")
  8. const getConvertPath = require("../util/get-convert-path")
  9. const getImportExportTargets = require("../util/get-import-export-targets")
  10. const getResolvePaths = require("../util/get-resolve-paths")
  11. const getTryExtensions = require("../util/get-try-extensions")
  12. module.exports = {
  13. meta: {
  14. docs: {
  15. description: "disallow `import` declarations of private things",
  16. category: "Possible Errors",
  17. recommended: false,
  18. url:
  19. "https://github.com/mysticatea/eslint-plugin-node/blob/v8.0.1/docs/rules/no-unpublished-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. tryExtensions: getTryExtensions.schema,
  31. },
  32. additionalProperties: false,
  33. },
  34. ],
  35. },
  36. create(context) {
  37. const filePath = context.getFilename()
  38. if (filePath === "<input>") {
  39. return {}
  40. }
  41. return {
  42. "Program:exit"(node) {
  43. checkPublish(
  44. context,
  45. filePath,
  46. getImportExportTargets(context, node)
  47. )
  48. },
  49. }
  50. },
  51. }