77 lines
2.6 KiB
JavaScript
77 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { execSync } from "node:child_process";
|
|
|
|
console.log("\n[Standards Verification] Running targeted inspection on modified files...\n");
|
|
|
|
let statusOutput = "";
|
|
try {
|
|
statusOutput = execSync("git status -s", { encoding: "utf-8" }).trim();
|
|
} catch (err) {
|
|
console.error("Error executing git status:", err.message);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (!statusOutput) {
|
|
console.log("✔ Working tree is clean. No changed files to inspect.");
|
|
process.exit(0);
|
|
}
|
|
|
|
const lines = statusOutput.split("\n");
|
|
const modifiedFiles = lines
|
|
.map((line) => line.slice(3).trim())
|
|
.filter((f) => fs.existsSync(f) && fs.statSync(f).isFile());
|
|
|
|
console.log(`Targeting ${modifiedFiles.length} modified file(s):`);
|
|
modifiedFiles.forEach((f) => console.log(` - ${f}`));
|
|
console.log("");
|
|
|
|
let issuesFound = 0;
|
|
|
|
for (const file of modifiedFiles) {
|
|
const content = fs.readFileSync(file, "utf-8");
|
|
|
|
// 1. CSS anti-patterns
|
|
if (file.endsWith(".css")) {
|
|
if (/backdrop-filter\s*:/i.test(content)) {
|
|
console.error(`✖ Violation in ${file}: Glassmorphism (backdrop-filter) is strictly forbidden.`);
|
|
issuesFound++;
|
|
}
|
|
const shadowMatches = content.match(/(box-shadow|text-shadow)\s*:\s*([^;]+);/gi) || [];
|
|
for (const match of shadowMatches) {
|
|
if (!/(box-shadow|text-shadow)\s*:\s*none\s*;/i.test(match)) {
|
|
console.error(`✖ Violation in ${file}: Drop shadows/glows forbidden: '${match}'`);
|
|
issuesFound++;
|
|
}
|
|
}
|
|
if (/(linear-gradient|radial-gradient|conic-gradient)/i.test(content)) {
|
|
console.error(`✖ Violation in ${file}: Gradients are strictly forbidden.`);
|
|
issuesFound++;
|
|
}
|
|
const radiusMatches = content.match(/border-radius\s*:\s*([^;]+);/gi) || [];
|
|
for (const match of radiusMatches) {
|
|
const pxMatch = match.match(/(\d+)\s*px/i);
|
|
if (pxMatch && parseInt(pxMatch[1], 10) > 4) {
|
|
console.error(`✖ Violation in ${file}: Border radius must be <= 4px: '${match}'`);
|
|
issuesFound++;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 2. Monolithic inline styles in templates
|
|
if (file.endsWith(".njk") || file.endsWith(".html")) {
|
|
if (/<style[^>]*>[\s\S]*?<\/style>/i.test(content)) {
|
|
console.error(`✖ Violation in ${file}: Monolithic inline <style> tags are forbidden. Modularize into src/assets/css/`);
|
|
issuesFound++;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (issuesFound > 0) {
|
|
console.error(`\n✖ Standards Verification failed: ${issuesFound} issue(s) detected.\n`);
|
|
process.exit(1);
|
|
} else {
|
|
console.log("✔ Targeted standards verification passed with 0 violations.\n");
|
|
}
|