no-restricted-require.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @author Christian Schulz
  3. * @author Toru Nagashima
  4. * See LICENSE file in root directory for full license.
  5. */
  6. "use strict"
  7. const check = require("../util/check-restricted")
  8. const visit = require("../util/visit-require")
  9. module.exports = {
  10. meta: {
  11. type: "suggestion",
  12. docs: {
  13. description: "disallow specified modules when loaded by `require`",
  14. category: "Stylistic Issues",
  15. recommended: false,
  16. url:
  17. "https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-restricted-require.md",
  18. },
  19. fixable: null,
  20. schema: [
  21. {
  22. type: "array",
  23. items: {
  24. anyOf: [
  25. { type: "string" },
  26. {
  27. type: "object",
  28. properties: {
  29. name: {
  30. anyOf: [
  31. { type: "string" },
  32. {
  33. type: "array",
  34. items: { type: "string" },
  35. additionalItems: false,
  36. },
  37. ],
  38. },
  39. message: { type: "string" },
  40. },
  41. additionalProperties: false,
  42. required: ["name"],
  43. },
  44. ],
  45. },
  46. additionalItems: false,
  47. },
  48. ],
  49. messages: {
  50. restricted:
  51. // eslint-disable-next-line @mysticatea/eslint-plugin/report-message-format
  52. "'{{name}}' module is restricted from being used.{{customMessage}}",
  53. },
  54. },
  55. create(context) {
  56. const opts = { includeCore: true }
  57. return visit(context, opts, targets => check(context, targets))
  58. },
  59. }