noProcessEnv
此内容尚不支持你的语言。
Summary
Section titled “Summary”- Rule available since:
v1.9.1
- Diagnostic Category:
lint/style/noProcessEnv
- This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
n/no-process-env
- Same as
Description
Section titled “Description”Disallow the use of process.env
.
The process.env
object in Node.js stores configuration settings. Using it directly throughout a project can cause problems:
- It’s harder to maintain
- It can lead to conflicts in team development
- It complicates deployment across multiple servers
A better practice is to keep all settings in one configuration file and reference it throughout the project.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”if (process.env.NODE_ENV === 'development') { // ...}
code-block.js:1:5 lint/style/noProcessEnv ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Don’t use process.env.
> 1 │ if (process.env.NODE_ENV === ‘development’) {
│ ^^^^^^^^^^^
2 │ // …
3 │ }
ℹ Use a centralized configuration file instead for better maintainability and deployment consistency.
const config = require('./config');if (config.NODE_ENV === 'development') { // ...}
How to configure
Section titled “How to configure”{ "linter": { "rules": { "style": { "noProcessEnv": "error" } } }}