Dotenv Suite
Require every value in .env and .env.sample files to be wrapped in double quotes with registerDotenvSuite.
Summary
- Scans the env files you list and reads each declared value.
- Flags any value that is single-quoted, unquoted, or left bare instead of double-quoted.
- Skips comments and blank lines, and accepts balanced multi-line double-quoted values.
Why Use This Suite?
- Keeps a single source of truth alongside the dotenv generator, which already writes every value double-quoted.
- Catches a hand-edited file that has drifted away from the convention during the test run.
- Holds the same quoting standard across the monorepo, so env files never vary from one project to the next.
Examples
Usage
src/tests/dotenv.test.ts
import { registerDotenvSuite } from '@cbnventures/nova/rules/vitest';
import * as vitest from 'vitest';
registerDotenvSuite({
vitest,
enable: 'all',
});
The defaults resolve envPaths against rootDir, scanning .env and .env.sample from the project root. In a monorepo, Vitest runs in the workspace directory but the .env can live at the repo root, so set rootDir to the repo root and list every env file in envPaths.
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
rootDir | string | process.cwd() | Base directory the envPaths resolve against. |
envPaths | string[] | ['.env', '.env.sample'] | Files scanned for violations; missing ones are skipped. |
enable | 'all' | ToggleKey[] | required | Which checks run. Use 'all' for every check, or a list. |
Toggle Keys
| Toggle Key | Description |
|---|---|
values-double-quoted | Requires every value in the targeted env files to be double-quoted. |
Troubleshooting
- Root
.envnot checked — SetrootDirto the repo root and list the file inenvPaths, since Vitest runs in the workspace directory. .dev.varsflagged — Only the entries inenvPathsare checked, so a.dev.varsfile is never targeted unless you add it.