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