noProcessEnv
¥Summary
-
规则生效日期:
v1.9.1¥Rule available since:
v1.9.1 -
¥Diagnostic Category:
lint/style/noProcessEnv -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
n/no-process-env相同¥Same as
n/no-process-env
-
¥How to configure
{ "linter": { "rules": { "style": { "noProcessEnv": "error" } } }}¥Description
禁止使用 process.env。
¥Disallow the use of process.env.
Node.js 中的 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
¥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.
¥Valid
const config = require('./config');if (config.NODE_ENV === 'development') { // ...}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号