text-decoder.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. TextDecoder: { [READ]: true },
  11. },
  12. modules: {
  13. util: {
  14. TextDecoder: { [READ]: true },
  15. },
  16. },
  17. }
  18. module.exports = {
  19. meta: {
  20. docs: {
  21. description:
  22. 'enforce either `TextDecoder` or `require("util").TextDecoder`',
  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/text-decoder.md",
  27. },
  28. type: "suggestion",
  29. fixable: null,
  30. schema: [{ enum: ["always", "never"] }],
  31. messages: {
  32. preferGlobal:
  33. "Unexpected use of 'require(\"util\").TextDecoder'. Use the global variable 'TextDecoder' instead.",
  34. preferModule:
  35. "Unexpected use of the global variable 'TextDecoder'. Use 'require(\"util\").TextDecoder' instead.",
  36. },
  37. },
  38. create(context) {
  39. return {
  40. "Program:exit"() {
  41. checkForPreferGlobal(context, trackMap)
  42. },
  43. }
  44. },
  45. }