no-process-env.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @author Vignesh Anand
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "suggestion",
  12. docs: {
  13. description: "disallow the use of `process.env`",
  14. category: "Stylistic Issues",
  15. recommended: false,
  16. url:
  17. "https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-process-env.md",
  18. },
  19. fixable: null,
  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. const propertyName = node.property.name
  30. if (
  31. objectName === "process" &&
  32. !node.computed &&
  33. propertyName &&
  34. propertyName === "env"
  35. ) {
  36. context.report({ node, messageId: "unexpectedProcessEnv" })
  37. }
  38. },
  39. }
  40. },
  41. }