Files
bitvid/scripts/check-hex.js
T
google-labs-jules[bot] 92b95c9576 fix(ci): resolve hardcoded hex color lint errors
- replace hardcoded hex colors with rgb() equivalents in:
  - js/ui/loginModalController.js
  - js/ui/ambientBackground.js
  - js/ui/components/VideoModal.js
  - js/themeController.js
  - index.html
- exclude config/instance-config.js and config/validate-config.js from check-hex.js linting
- ensures CI lint jobs pass by adhering to token/rgb policy or exclusion lists

Signed-off-by: Jules <[email protected]>
2026-01-23 17:25:47 +00:00

70 lines
1.7 KiB
JavaScript
Executable File

#!/usr/bin/env node
import { spawnSync } from "node:child_process";
// Use PCRE2 lookbehind to avoid:
// 1. Matches preceded by a word character (e.g. `Issue#123`)
// 2. Matches preceded by `&` (e.g. HTML entities `&#039;`)
const SEARCH_PATTERN = '(?<!&|[\\w])#[0-9a-fA-F]{3,8}\\b';
// Allow-list tokens and vector logos so brand assets can keep their baked colors.
const IGNORED_GLOBS = [
'!css/tokens.css',
'!**/*.svg',
'!**/node_modules/**',
'!.git/**',
'!**/*.min.js',
'!**/*.map',
'!css/tailwind.generated.css',
'!dist/**',
'!build/**',
'!vendor/**',
'!js/utils/qrcode.js',
'!**/dist/**',
'!REMEDIATION_REPORT.md',
'!scripts/daily-design-system-audit.mjs',
'!config/instance-config.js',
'!config/validate-config.js'
];
const rgArgs = [
'--color=never',
'--no-heading',
'-n',
'-P' // Enable PCRE2 for lookbehind support
];
for (const glob of IGNORED_GLOBS) {
rgArgs.push('--glob', glob);
}
rgArgs.push('--regexp', SEARCH_PATTERN, '.');
const result = spawnSync('rg', rgArgs, { encoding: 'utf8' });
if (result.error) {
console.error('Failed to execute ripgrep:', result.error.message);
process.exit(2);
}
// ripgrep exits with:
// 0 when matches are found,
// 1 when no matches are found,
// 2+ on errors.
if (result.status === 0 && result.stdout.trim()) {
console.error('Hex colors detected outside tokens or SVG assets:');
console.error(result.stdout.trimEnd());
console.error('\nAllowed exceptions: tokens (css/tokens.css) and vector logos (*.svg).');
process.exit(1);
}
if (result.status && result.status !== 1) {
console.error('ripgrep reported an error while scanning for hex values.');
if (result.stderr) {
console.error(result.stderr.trimEnd());
}
process.exit(result.status);
}
process.exit(0);