Skip to content

A library of Agent Skills designed to work with the Stitch MCP server. Each skill follows the Agent Skills open standard, for compatibility with coding agents such as Antigravity, Gemini CLI, Claude Code, Cursor.

TypeScript

perf: avoid creating regex inside loop in validate.js

davideast982115ddccd7
diff --git a/skills/react-components/scripts/validate.js b/skills/react-components/scripts/validate.js
index 1df3caa..62ed4f4 100644
--- a/skills/react-components/scripts/validate.js
+++ b/skills/react-components/scripts/validate.js
@@ -18,6 +18,8 @@ import swc from '@swc/core';
import fs from 'node:fs';
import path from 'node:path';
+const HEX_COLOR_REGEX = /#[0-9A-Fa-f]{6}/;
+
async function validateComponent(filePath) {
const code = fs.readFileSync(filePath, 'utf-8');
const filename = path.basename(filePath);
@@ -32,7 +34,7 @@ async function validateComponent(filePath) {
if (!node) return;
if (node.type === 'TsInterfaceDeclaration' && node.id.value.endsWith('Props')) hasInterface = true;
if (node.type === 'JSXAttribute' && node.name.name === 'className') {
- if (node.value?.value && /#[0-9A-Fa-f]{6}/.test(node.value.value)) tailwindIssues.push(node.value.value);
+ if (node.value?.value && HEX_COLOR_REGEX.test(node.value.value)) tailwindIssues.push(node.value.value);
}
for (const key in node) { if (node[key] && typeof node[key] === 'object') walk(node[key]); }
};