no-unpublished-import.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @author Toru Nagashima
  3. * @copyright 2016 Toru Nagashima. All rights reserved.
  4. * See LICENSE file in root directory for full license.
  5. */
  6. "use strict"
  7. //------------------------------------------------------------------------------
  8. // Requirements
  9. //------------------------------------------------------------------------------
  10. const checkPublish = require("../util/check-publish")
  11. const getAllowModules = require("../util/get-allow-modules")
  12. const getConvertPath = require("../util/get-convert-path")
  13. const getDocsUrl = require("../util/get-docs-url")
  14. const getImportExportTargets = require("../util/get-import-export-targets")
  15. const getResolvePaths = require("../util/get-resolve-paths")
  16. const getTryExtensions = require("../util/get-try-extensions")
  17. //------------------------------------------------------------------------------
  18. // Helpers
  19. //------------------------------------------------------------------------------
  20. /**
  21. * The definition of this rule.
  22. *
  23. * @param {RuleContext} context - The rule context to check.
  24. * @returns {object} The definition of this rule.
  25. */
  26. function create(context) {
  27. const filePath = context.getFilename()
  28. if (filePath === "<input>") {
  29. return {}
  30. }
  31. return {
  32. "Program:exit"(node) {
  33. checkPublish(
  34. context,
  35. filePath,
  36. getImportExportTargets(context, node)
  37. )
  38. },
  39. }
  40. }
  41. //------------------------------------------------------------------------------
  42. // Rule Definition
  43. //------------------------------------------------------------------------------
  44. module.exports = {
  45. create,
  46. meta: {
  47. docs: {
  48. description: "disallow `import` declarations of private things",
  49. category: "Possible Errors",
  50. recommended: false,
  51. url: getDocsUrl("no-unpublished-import.md"),
  52. },
  53. fixable: false,
  54. schema: [
  55. {
  56. type: "object",
  57. properties: {
  58. allowModules: getAllowModules.schema,
  59. convertPath: getConvertPath.schema,
  60. resolvePaths: getResolvePaths.schema,
  61. tryExtensions: getTryExtensions.schema,
  62. },
  63. additionalProperties: false,
  64. },
  65. ],
  66. },
  67. }