url.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. URL: { [READ]: true },
  11. },
  12. modules: {
  13. url: {
  14. URL: { [READ]: true },
  15. },
  16. },
  17. }
  18. module.exports = {
  19. meta: {
  20. docs: {
  21. description: 'enforce either `URL` or `require("url").URL`',
  22. category: "Stylistic Issues",
  23. recommended: false,
  24. url:
  25. "https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/prefer-global/url.md",
  26. },
  27. type: "suggestion",
  28. fixable: null,
  29. schema: [{ enum: ["always", "never"] }],
  30. messages: {
  31. preferGlobal:
  32. "Unexpected use of 'require(\"url\").URL'. Use the global variable 'URL' instead.",
  33. preferModule:
  34. "Unexpected use of the global variable 'URL'. Use 'require(\"url\").URL' instead.",
  35. },
  36. },
  37. create(context) {
  38. return {
  39. "Program:exit"() {
  40. checkForPreferGlobal(context, trackMap)
  41. },
  42. }
  43. },
  44. }