no-unpublished-require.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 getRequireTargets = require("../util/get-require-targets")
  14. const getResolvePaths = require("../util/get-resolve-paths")
  15. const getTryExtensions = require("../util/get-try-extensions")
  16. //------------------------------------------------------------------------------
  17. // Helpers
  18. //------------------------------------------------------------------------------
  19. /**
  20. * The definition of this rule.
  21. *
  22. * @param {RuleContext} context - The rule context to check.
  23. * @returns {object} The definition of this rule.
  24. */
  25. function create(context) {
  26. const filePath = context.getFilename()
  27. if (filePath === "<input>") {
  28. return {}
  29. }
  30. return {
  31. "Program:exit"() {
  32. checkPublish(
  33. context,
  34. filePath,
  35. getRequireTargets(context)
  36. )
  37. },
  38. }
  39. }
  40. //------------------------------------------------------------------------------
  41. // Rule Definition
  42. //------------------------------------------------------------------------------
  43. module.exports = {
  44. create,
  45. meta: {
  46. docs: {
  47. description: "disallow `require()` expressions of private things",
  48. category: "Possible Errors",
  49. recommended: true,
  50. },
  51. fixable: false,
  52. schema: [
  53. {
  54. type: "object",
  55. properties: {
  56. allowModules: getAllowModules.schema,
  57. convertPath: getConvertPath.schema,
  58. resolvePaths: getResolvePaths.schema,
  59. tryExtensions: getTryExtensions.schema,
  60. },
  61. additionalProperties: false,
  62. },
  63. ],
  64. },
  65. }