no-process-env.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @fileoverview Disallow the use of process.env()
  3. * @author Vignesh Anand
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. deprecated: true,
  12. replacedBy: [],
  13. type: "suggestion",
  14. docs: {
  15. description: "disallow the use of `process.env`",
  16. category: "Node.js and CommonJS",
  17. recommended: false,
  18. url: "https://eslint.org/docs/rules/no-process-env"
  19. },
  20. schema: [],
  21. messages: {
  22. unexpectedProcessEnv: "Unexpected use of process.env."
  23. }
  24. },
  25. create(context) {
  26. return {
  27. MemberExpression(node) {
  28. const objectName = node.object.name,
  29. propertyName = node.property.name;
  30. if (objectName === "process" && !node.computed && propertyName && propertyName === "env") {
  31. context.report({ node, messageId: "unexpectedProcessEnv" });
  32. }
  33. }
  34. };
  35. }
  36. };