UNPKG

env-sentinel

Version:

Zero-dependency tool that auto-validates .env files against schema.env, with optional fallback and secure warnings.

22 lines (21 loc) 681 B
import { isEmptyOrCommentLine } from '../utils.js'; export function noInvalidKeyLeadingCharCheck(lineNumber, lineContent) { if (isEmptyOrCommentLine(lineContent)) { return; } const [rawKey] = lineContent.split('='); const trimmedKey = rawKey.trim().replace(/^['"]|['"]$/g, ''); if (trimmedKey === '') { return; } const firstChar = trimmedKey.charAt(0); if (!/[A-Za-z_]/.test(firstChar)) { return { line: lineNumber, issue: `Variable name starts with invalid character: "${firstChar}" in "${trimmedKey}"`, content: lineContent, severity: 'error', }; } return; }