UNPKG

env-sentinel

Version:

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

55 lines (54 loc) 1.64 kB
import { lintRegistry } from './lint-registry.js'; import { parseDisabledRules } from './utils.js'; export function lint(envContent) { const lines = envContent.split(/\r?\n/); const issues = []; let errors = 0; let warnings = 0; let notices = 0; const disabledRules = parseDisabledRules(lines); const lintChecks = lintRegistry.getAll(); lines.forEach((rawLine, idx) => { const lineNumber = idx + 1; lintChecks.forEach((check) => { if (disabledRules?.get(lineNumber)?.has(check.name)) { return; } if (rawLine.trim().startsWith('#')) { return; } const checkResult = check.run(lineNumber, rawLine); if (checkResult !== undefined) { const severity = checkResult.severity || 'error'; issues.push({ line: lineNumber, message: checkResult.issue, severity, rule: check.name, }); switch (severity) { case 'error': errors++; break; case 'warning': warnings++; break; case 'notice': notices++; break; } } }); }); const summary = { total: issues.length, errors, warnings, notices, }; return { isValid: errors === 0, issues, summary, }; }