Skip to content

Commit 8979915

Browse files
committed
feat: add verbose mode to survey validation script and implement error-only formatting
1 parent 054e582 commit 8979915

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

scripts/validate-survey.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,43 @@
66

77
import { SURVEY_DIR } from "../src/lib/validators/constants";
88
import {
9+
formatErrorsOnly,
910
formatValidationReport,
1011
validateAllSurveyFiles
1112
} from "../src/lib/validators/survey-validator";
1213

1314
async function main() {
15+
// Check for --verbose flag
16+
const isVerbose = process.argv.includes("--verbose");
17+
1418
console.log("🔍 Validating survey YAML files...\n");
1519

1620
const validationReport = validateAllSurveyFiles(SURVEY_DIR);
1721

18-
console.log(formatValidationReport(validationReport));
22+
if (isVerbose) {
23+
// Verbose mode: show full report
24+
console.log(formatValidationReport(validationReport));
25+
}
26+
else {
27+
// Default mode: show only errors or success message
28+
if (validationReport.success) {
29+
// No errors, just show success
30+
console.log("✓ All validations passed!");
31+
process.exit(0);
32+
}
33+
else {
34+
// Show only ERROR-level issues
35+
const errorsOutput = formatErrorsOnly(validationReport);
36+
if (errorsOutput) {
37+
console.log(errorsOutput);
38+
}
39+
}
40+
}
1941

2042
if (validationReport.success) {
21-
console.log("\n✓ All validations passed!");
43+
if (isVerbose) {
44+
console.log("\n✓ All validations passed!");
45+
}
2246
process.exit(0);
2347
}
2448
else {

src/components/google-analytics.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const gtagUrl = `https://www.googletagmanager.com/gtag/js?id=${id}`;
99
---
1010

1111
<!-- Global site tag (gtag.js) - Google Analytics -->
12-
<script async src={gtagUrl}></script>
12+
<script is:inline async src={gtagUrl}></script>
1313
<script define:vars={{ id }} is:inline>
1414
window.dataLayer = window.dataLayer || [];
1515
function gtag(...args) {

src/lib/validators/survey-validator.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,56 @@ const colors = {
480480
cyan: "\x1B[36m"
481481
};
482482

483+
/**
484+
* Formats only ERROR-level validation issues in a concise format
485+
* @param report - Validation report to format
486+
* @returns Formatted string with only errors (no warnings)
487+
*/
488+
export function formatErrorsOnly(report: ValidationReport): string {
489+
const lines: string[] = [];
490+
491+
// Collect all ERROR-level issues from file results
492+
const fileErrors = report.fileResults.filter(
493+
result => result.errors?.some(e => e.severity === ValidationSeverity.ERROR)
494+
);
495+
496+
if (fileErrors.length > 0) {
497+
lines.push(`${colors.red}✗ Validation errors found:${colors.reset}`);
498+
lines.push("");
499+
500+
for (const result of fileErrors) {
501+
const errors = result.errors?.filter(
502+
e => e.severity === ValidationSeverity.ERROR
503+
) || [];
504+
505+
if (errors.length > 0) {
506+
lines.push(`${colors.bright}File: ${result.filename}${colors.reset}`);
507+
errors.forEach((error) => {
508+
const pathInfo = error.path ? ` [${error.path}]` : "";
509+
lines.push(` ${colors.red}${colors.reset} ${error.message}${pathInfo}`);
510+
});
511+
lines.push("");
512+
}
513+
}
514+
}
515+
516+
// Collect ERROR-level cross-file issues
517+
const crossFileErrors = report.crossFileErrors.filter(
518+
e => e.severity === ValidationSeverity.ERROR
519+
);
520+
521+
if (crossFileErrors.length > 0) {
522+
lines.push(`${colors.bright}Cross-file errors:${colors.reset}`);
523+
crossFileErrors.forEach((error) => {
524+
const pathInfo = error.path ? ` [${error.path}]` : "";
525+
lines.push(` ${colors.red}${colors.reset} ${error.message}${pathInfo}`);
526+
});
527+
lines.push("");
528+
}
529+
530+
return lines.join("\n");
531+
}
532+
483533
/**
484534
* Formats validation report as a human-readable string with colors
485535
* @param report - Validation report to format

0 commit comments

Comments
 (0)