From 2d8ad1faa715c09ce3d42bbc5c9e40aff29b4063 Mon Sep 17 00:00:00 2001 From: Liyfez Date: Sun, 29 Nov 2026 22:03:59 +0500 Subject: [PATCH] fix(linter): skip contrast check for translucent colors --- .../cli/src/linter/linter/rules/contrast-ratio.test.ts | 10 ++++++++++ packages/cli/src/linter/linter/rules/contrast-ratio.ts | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/packages/cli/src/linter/linter/rules/contrast-ratio.test.ts b/packages/cli/src/linter/linter/rules/contrast-ratio.test.ts index e8c911b4..242924e0 100644 --- a/packages/cli/src/linter/linter/rules/contrast-ratio.test.ts +++ b/packages/cli/src/linter/linter/rules/contrast-ratio.test.ts @@ -29,6 +29,16 @@ describe('contrastCheck', () => { expect(findings[0]!.message).toMatch(/contrast/); }); + it('does not judge a translucent background without a known backdrop', () => { + const state = buildState({ + colors: { surface: '#1a1d21', warn: '#f2b33d', 'warn-tint': '#f2b33d1a' }, + components: { + 'alert-tint': { backgroundColor: '{colors.warn-tint}', textColor: '{colors.warn}' }, + }, + }); + expect(contrastCheck(state)).toEqual([]); + }); + it('returns empty for high contrast pair', () => { const state = buildState({ colors: { black: '#000000', white: '#ffffff' }, diff --git a/packages/cli/src/linter/linter/rules/contrast-ratio.ts b/packages/cli/src/linter/linter/rules/contrast-ratio.ts index 22856490..9056a0b8 100644 --- a/packages/cli/src/linter/linter/rules/contrast-ratio.ts +++ b/packages/cli/src/linter/linter/rules/contrast-ratio.ts @@ -33,6 +33,12 @@ export function contrastCheck(state: DesignSystemState): RuleFinding[] { const textColor = resolveToColor(textValue); if (!bgColor || !textColor) continue; + // A translucent color's contrast depends on what it is composited over. + // The rule has no backdrop for a component, so comparing the raw color + // produces false warnings (for example a 10% tint against its own text). + // Leave those pairs to manual review instead of guessing a surface. + if ((bgColor.a ?? 1) < 1 || (textColor.a ?? 1) < 1) continue; + const ratio = contrastRatio(bgColor, textColor); if (ratio < WCAG_AA_MINIMUM) { findings.push({