Skip to main content

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?

  1. Keeps a single source of truth alongside the dotenv generator, which already writes every value double-quoted.
  2. Catches a hand-edited file that has drifted away from the convention during the test run.
  3. 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
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

FieldTypeDefaultDescription
rootDirstringprocess.cwd()Base directory the envPaths resolve against.
envPathsstring[]['.env', '.env.sample']Files scanned for violations; missing ones are skipped.
enable'all' | ToggleKey[]requiredWhich checks run. Use 'all' for every check, or a list.

Toggle Keys

Toggle KeyDescription
values-double-quotedRequires every value in the targeted env files to be double-quoted.

Troubleshooting

  • Root .env not checked — Set rootDir to the repo root and list the file in envPaths, since Vitest runs in the workspace directory.
  • .dev.vars flagged — Only the entries in envPaths are checked, so a .dev.vars file is never targeted unless you add it.