buffer.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @author Toru Nagashima
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const { READ } = require("eslint-utils")
  7. const checkForPreferGlobal = require("../../util/check-prefer-global")
  8. const trackMap = {
  9. globals: {
  10. Buffer: { [READ]: true },
  11. },
  12. modules: {
  13. buffer: {
  14. Buffer: { [READ]: true },
  15. },
  16. },
  17. }
  18. module.exports = {
  19. meta: {
  20. docs: {
  21. description:
  22. 'enforce either `Buffer` or `require("buffer").Buffer`',
  23. category: "Stylistic Issues",
  24. recommended: false,
  25. url:
  26. "https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/prefer-global/buffer.md",
  27. },
  28. type: "suggestion",
  29. fixable: null,
  30. schema: [{ enum: ["always", "never"] }],
  31. messages: {
  32. preferGlobal:
  33. "Unexpected use of 'require(\"buffer\").Buffer'. Use the global variable 'Buffer' instead.",
  34. preferModule:
  35. "Unexpected use of the global variable 'Buffer'. Use 'require(\"buffer\").Buffer' instead.",
  36. },
  37. },
  38. create(context) {
  39. return {
  40. "Program:exit"() {
  41. checkForPreferGlobal(context, trackMap)
  42. },
  43. }
  44. },
  45. }