Перейти до вмісту

noUndeclaredEnvVars

Цей контент ще не доступний вашою мовою.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noUndeclaredEnvVars": "error"
}
}
}
}

Disallow the use of undeclared environment variables.

In Turborepo projects, environment variables used in tasks must be declared in the turbo.json(c) configuration file to ensure proper caching behavior. Using undeclared environment variables can lead to incorrect cache hits and unpredictable build behavior.

This rule checks for process.env.VAR_NAME and import.meta.env.VAR_NAME accesses and validates them against:

  1. Environment variables declared in turbo.json(c) (globalEnv, globalPassThroughEnv, task-level env, and task-level passThroughEnv)
  2. Environment variables specified in the rule’s allowedEnvVars option
  3. Default allowed variables (common system vars and framework-specific patterns)

The following environment variables are always allowed without explicit declaration:

System variables:

  • CI, HOME, PATH, PWD, SHELL, TZ, USER

Node.js:

  • NODE_ENV

Framework and provider-specific patterns (all variables matching these prefixes):

  • NEXT_PUBLIC_* (Next.js)
  • VITE_* (Vite)
  • REACT_APP_* (Create React App)
  • VUE_APP_* (Vue CLI)
  • NUXT_* (Nuxt)
  • GATSBY_* (Gatsby)
  • EXPO_PUBLIC_* (Expo)
  • VERCEL, VERCEL_* (Vercel)

When MY_VAR is not declared in turbo.json or the allowed list:

const value = process.env.MY_VAR;
// NODE_ENV is always allowed
const value = process.env.NODE_ENV;

Use the options to specify additional environment variables that are not declared in globalEnv, globalPassThroughEnv, or task-level env/passThroughEnv in turbo.json. Supports regular expression patterns (anchors ^ and $ are implicit).

biome.json
{
"linter": {
"rules": {
"nursery": {
"noUndeclaredEnvVars": {
"options": {
"allowedEnvVars": [
"MY_APP_.*",
"ACME_TOKEN"
]
}
}
}
}
}
}