console.js 1.2 KB

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