Linting

Catch unused, missing, or inconsistent environment variables automatically with powerful linting tools.

Why Linting Matters

Even small mistakes in .env files can cause production failures:

  • Misspelled or duplicated keys
  • Unsafe shell characters
  • Hidden YAML pitfalls (on, off, yes, no)
  • Unescaped quotes or multiline values

env-sentinel lint catches these issues before they cause damage.


Basic Usage

Run linting on your default .env file:

npx env-sentinel lint

Lint a specific file:

npx env-sentinel lint --file .env.production

What It Checks

  • Invalid or unsafe characters in keys and values
  • Missing or empty values
  • Duplicate keys or references
  • Unescaped shell tokens like $, !, &
  • YAML boolean literals (true, false, yes, no, etc.)
  • Whitespace and formatting problems

Built-in Linting Rules

Below is a list of all built-in linting checks:

RuleDescriptionSeverity
no-leading-spacesChecks for leading spaces in key nameserror
no-empty-valueDetects empty values for keyserror
no-missing-keyEnsures every line has a keyerror
no-duplicate-keyPrevents duplicate keys in .enverror
no-invalid-key-delimiterChecks for invalid key=value delimiter usageerror
no-invalid-key-leading-charDetects invalid leading characters in keyserror
no-invalid-key-charactersDetects invalid characters in keyserror
no-whitespace-in-keyChecks for spaces in key nameswarning
no-lowercase-in-keyEnsures keys are uppercasenotice
no-unsafe-keyDetects unsafe characters in keyswarning
no-quoted-keyPrevents quoted keyswarning
no-space-before-equalChecks for space before = in key=valuewarning
no-space-after-equalChecks for space after = in key=valuewarning
no-invalid-reference-syntaxDetects invalid variable reference syntaxerror
no-unquoted-multiline-valueDetects multiline values that are not quotederror
no-unescaped-shell-charsDetects unescaped shell-special characterserror
no-yaml-boolean-literalDetects YAML-style booleans in valueswarning
no-empty-quotesDetects empty quotesnotice
no-duplicate-referenceDetects duplicate variable referenceswarning
no-comma-separated-value-in-scalarDetects comma-separated values in scalar contextwarning

Example Output

.env:5 [error] no-missing-key → Variable name is missing
.env:8 [warning] no-unescaped-shell-chars → Unescaped shell characters in value
.env:12 [notice] no-empty-value → Variable "COMMENTED_OUT" has an empty value
  • ✅ Errors must be fixed
  • ⚠️ Warnings highlight risky practices
  • 💡 Notices are suggestions for improvement

CI/CD Integration

Linting can be added as a pre-commit hook or CI step:

{
  "scripts": {
    "lint:env": "env-sentinel lint --file .env"
  }
}

In CI (GitHub Actions example):

- name: Lint .env files
  run: npx env-sentinel lint --file .env.production

Next Steps

  • Explore Validation to enforce variable types.
  • Learn how to Document your configuration for better team workflows.

With env-sentinel, your .env files stay consistent, safe, and production-ready.