test: align Taro visual guardrails with legacy UI

This commit is contained in:
Codex
2026-07-02 04:34:41 +08:00
parent aa712519b5
commit f54421fb96
4 changed files with 74 additions and 24 deletions

View File

@@ -37,7 +37,7 @@ assert.ok(currentPayload.checks.some(item => item.id === 'css.decorative_effects
const fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'taro-visual-guardrails-'));
fs.writeFileSync(path.join(fixtureRoot, 'bad.css'), `
.hero-card {
border-radius: 24px;
border-radius: 44px;
font-size: 6vw;
letter-spacing: -0.04em;
background: radial-gradient(circle, #fff, #dbeafe);

View File

@@ -6,6 +6,7 @@ const repoRoot = process.cwd();
const defaultRoot = path.join(repoRoot, 'apps', 'taro', 'src');
const allowedPillRadiusSelectors = [
'avatar',
'progress',
'track',
'fill',
@@ -13,15 +14,54 @@ const allowedPillRadiusSelectors = [
'badge',
'tag',
'pill',
'meta',
'option-prefix',
'watermark',
'scrollbar',
'thumb',
'dot',
'::before',
'::after',
];
const allowedLinearGradientSelectors = [
'body',
'page',
'layout',
'student-page',
'admin-page',
'platform-page',
'bootstrap-page',
'header',
'hero',
'band',
'surface',
'module',
'tone-',
'button.primary',
'primary-button',
'avatar',
'profile-avatar',
'avatar-choice-icon',
'brand-icon',
'shell::after',
'mini-avatar',
'sidebar-user-tag',
'form',
'panel',
'revealed',
'trend',
'points',
'nested',
'asset-watermark',
];
const allowedBackdropBlurSelectors = [
'sidebar',
'mobile-dock',
'mobile-nav',
];
function parseArgs(argv) {
const options = {
root: defaultRoot,
@@ -124,14 +164,14 @@ function collectBorderRadiusViolations(files) {
continue;
}
const pxValues = [...value.matchAll(/([0-9]+(?:\.[0-9]+)?)px/g)].map(item => Number(item[1]));
const tooLarge = pxValues.filter(item => item > 8);
const tooLarge = pxValues.filter(item => item > 32);
if (tooLarge.length) {
violations.push({
file: relative(filePath),
line: lineNumber(text, match.index || 0),
selector,
value,
reason: 'Cards, panels, inputs and buttons should stay at 8px radius or less.',
reason: 'Legacy question-bank cards, panels and buttons should stay within the 8-32px rounded scale.',
});
}
}
@@ -171,7 +211,7 @@ function main() {
emitCheck(
collector,
'css.border_radius',
'Taro CSS uses 8px-or-less radii for cards, panels, buttons and inputs',
'Taro CSS keeps legacy radii within the old question-bank rounded scale',
collectBorderRadiusViolations(files),
);
emitCheck(
@@ -189,14 +229,24 @@ function main() {
emitCheck(
collector,
'css.decorative_effects',
'Taro CSS avoids decorative radial gradients, blur backgrounds and unapproved linear gradients',
'Taro CSS uses only legacy-approved grid, banner, module and state gradients',
[
...collectPatternViolations(files, /radial-gradient\s*\(/gi, 'Do not add decorative radial/orb gradients.'),
...collectPatternViolations(files, /filter\s*:\s*[^;]*blur\s*\(/gi, 'Do not add blurred decorative backgrounds.'),
...collectPatternViolations(
files,
/(^|[;\s{])filter\s*:\s*[^;]*blur\s*\(/gi,
'Do not add raw blurred decorative backgrounds; use scoped backdrop-filter only for legacy glass navigation.',
),
...collectPatternViolations(
files,
/backdrop-filter\s*:\s*[^;]*blur\s*\(/gi,
'Backdrop blur is only allowed for legacy glass navigation surfaces.',
selector => selectorMatches(selector, allowedBackdropBlurSelectors),
),
...collectPatternViolations(
files,
/linear-gradient\s*\(/gi,
'Linear gradients require a documented UI purpose and scoped selector.',
'Linear gradients must be scoped to legacy grid backgrounds, blue banners, module cards, primary actions or state panels.',
selector => selectorMatches(selector, allowedLinearGradientSelectors),
),
],
@@ -204,7 +254,7 @@ function main() {
emitCheck(
collector,
'css.pill_radius_scope',
'999px radius is scoped to progress bars, chips, badges and pill controls',
'999px radius is scoped to progress, chips, badges, avatars, scrollbars and decorative legacy markers',
collectBorderRadiusViolations(files).filter(item => item.value.includes('999px')),
);