MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / validate

Function validate

src/platform/node-hyperscript.js:58–116  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', 'build', 'vendor', '__pycache__', '_site']);
57
58function validate() {
59 // Parse --ext flag
60 const extFlag = getFlagValue('--ext');
61 const extensions = new Set(DEFAULT_EXTENSIONS);
62 if (extFlag) {
63 for (const e of extFlag.split(',')) {
64 extensions.add(e.startsWith('.') ? e : '.' + e);
65 }
66 }
67
68 // Parse --attr flag (additional attributes beyond the defaults)
69 const defaultAttrs = ['_', 'script', 'data-script'];
70 const attrFlag = getFlagValue('--attr');
71 const attrs = [...defaultAttrs];
72 if (attrFlag) {
73 for (const a of attrFlag.split(',')) {
74 if (a.trim()) attrs.push(a.trim());
75 }
76 }
77
78 const quiet = flags.has('--quiet');
79
80 // Build regex from attributes
81 const attrPattern = new RegExp('\\b(' + attrs.map(escapeRegex).join('|') + ')\\s*=\\s*(["\'])', 'g');
82 const scriptPattern = /<script\s+type\s*=\s*["']text\/hyperscript["'][^>]*>([\s\S]*?)<\/script>/gi;
83
84 // Collect files
85 const targets = positional.length ? positional : ['.'];
86 const files = [];
87 for (const target of targets) {
88 collectFiles(path.resolve(target), extensions, files);
89 }
90
91 if (!files.length) {
92 console.log('No files found to validate.');
93 return;
94 }
95
96 // Validate
97 let totalErrors = 0;
98 let filesWithErrors = 0;
99
100 for (const filePath of files) {
101 const errors = validateFile(filePath, extensions, attrPattern, scriptPattern);
102 if (errors.length) {
103 filesWithErrors++;
104 totalErrors += errors.length;
105 if (!quiet) {
106 for (const msg of errors) console.error(msg);
107 }
108 }
109 }
110
111 // Summary
112 const color = totalErrors ? '\x1b[31m' : '\x1b[32m';
113 const reset = '\x1b[0m';
114 console.log(`\n${color}Validated ${files.length} file(s), ${totalErrors} error(s) in ${filesWithErrors} file(s).${reset}`);
115 process.exit(totalErrors ? 1 : 0);

Callers 1

Calls 4

getFlagValueFunction · 0.70
collectFilesFunction · 0.70
validateFileFunction · 0.70
resolveMethod · 0.45

Tested by

no test coverage detected