no-restricted-import.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @author Toru Nagashima
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const { checkForRestriction, messages } = require("../util/check-restricted")
  7. const visit = require("../util/visit-import")
  8. module.exports = {
  9. meta: {
  10. type: "suggestion",
  11. docs: {
  12. description:
  13. "disallow specified modules when loaded by `import` declarations",
  14. category: "Stylistic Issues",
  15. recommended: false,
  16. url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/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. },
  50. create(context) {
  51. const opts = { includeCore: true }
  52. return visit(context, opts, targets =>
  53. checkForRestriction(context, targets)
  54. )
  55. },
  56. }