no-process-env.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @fileoverview Disallow the use of process.env()
  3. * @author Vignesh Anand
  4. * @deprecated in ESLint v7.0.0
  5. */
  6. "use strict";
  7. //------------------------------------------------------------------------------
  8. // Rule Definition
  9. //------------------------------------------------------------------------------
  10. /** @type {import('../types').Rule.RuleModule} */
  11. module.exports = {
  12. meta: {
  13. deprecated: {
  14. message: "Node.js rules were moved out of ESLint core.",
  15. url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
  16. deprecatedSince: "7.0.0",
  17. availableUntil: "11.0.0",
  18. replacedBy: [
  19. {
  20. message:
  21. "eslint-plugin-n now maintains deprecated Node.js-related rules.",
  22. plugin: {
  23. name: "eslint-plugin-n",
  24. url: "https://github.com/eslint-community/eslint-plugin-n",
  25. },
  26. rule: {
  27. name: "no-process-env",
  28. url: "https://github.com/eslint-community/eslint-plugin-n/tree/master/docs/rules/no-process-env.md",
  29. },
  30. },
  31. ],
  32. },
  33. type: "suggestion",
  34. docs: {
  35. description: "Disallow the use of `process.env`",
  36. recommended: false,
  37. url: "https://eslint.org/docs/latest/rules/no-process-env",
  38. },
  39. schema: [],
  40. messages: {
  41. unexpectedProcessEnv: "Unexpected use of process.env.",
  42. },
  43. },
  44. create(context) {
  45. return {
  46. MemberExpression(node) {
  47. const objectName = node.object.name,
  48. propertyName = node.property.name;
  49. if (
  50. objectName === "process" &&
  51. !node.computed &&
  52. propertyName &&
  53. propertyName === "env"
  54. ) {
  55. context.report({ node, messageId: "unexpectedProcessEnv" });
  56. }
  57. },
  58. };
  59. },
  60. };