MCPcopy Create free account
hub / github.com/SethGammon/Citadel / lensAdversarial

Function lensAdversarial

hooks_src/quality-gate.js:286–350  ·  view source on GitHub ↗
(file, content)

Source from the content-addressed store, hash-verified

284// ── Accessibility Lens ──────────────────────────────────────────────────────
285
286function lensAccessibility(file, content) {
287 if (!/\.(tsx|jsx)$/.test(file)) return [];
288
289 const violations = [];
290
291 // Check for onClick on non-button elements without role/tabIndex
292 const onClickDivRegex = /<(?:div|span|a(?!\s+href))\s[^>]*onClick[^>]*>/g;
293 let match;
294 while ((match = onClickDivRegex.exec(content)) !== null) {
295 const tag = match[0];
296 if (!tag.includes('role=') && !tag.includes('tabIndex')) {
297 violations.push({
298 file,
299 lens: 'accessibility',
300 message: 'Interactive element with onClick but missing role and tabIndex',
301 });
302 break; // One warning per file to avoid noise
303 }
304 }
305
306 // Check for img tags without alt attribute
307 const imgNoAlt = /<img\s(?![^>]*alt=)[^>]*>/;
308 if (imgNoAlt.test(content)) {
309 violations.push({
310 file,
311 lens: 'accessibility',
312 message: 'img element without alt attribute',
313 });
314 }
315
316 // Check for icon-only buttons without aria-label
317 const iconButtonRegex = /<button\s(?![^>]*aria-label)[^>]*>[\s]*<(?:svg|Icon|img)/;
318 if (iconButtonRegex.test(content)) {
319 violations.push({
320 file,
321 lens: 'accessibility',
322 message: 'Icon-only button without aria-label',
323 });
324 }
325
326 return violations;
327}
328
329// ── Adversarial Lens ────────────────────────────────────────────────────────
330
331function lensAdversarial(file, content) {
332 const violations = [];
333
334 if (/\.(ts|tsx|js|jsx)$/.test(file)) {
335 // Check for dangerouslySetInnerHTML
336 if (/dangerouslySetInnerHTML/.test(content)) {
337 violations.push({
338 file,
339 lens: 'adversarial',
340 message: 'Uses dangerouslySetInnerHTML — verify input is sanitized',
341 });
342 }
343

Callers 1

runColdLensFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected