no-restricted-import.js 2.0 KB

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