no-process-env.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-process-env.md",
  17. },
  18. fixable: null,
  19. schema: [],
  20. messages: {
  21. unexpectedProcessEnv: "Unexpected use of process.env.",
  22. },
  23. },
  24. create(context) {
  25. return {
  26. MemberExpression(node) {
  27. const objectName = node.object.name
  28. const propertyName = node.property.name
  29. if (
  30. objectName === "process" &&
  31. !node.computed &&
  32. propertyName &&
  33. propertyName === "env"
  34. ) {
  35. context.report({ node, messageId: "unexpectedProcessEnv" })
  36. }
  37. },
  38. }
  39. },
  40. }