[READ-ONLY] a fast, modern browser for the npm registry
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: deduplicate RTL warnings in uno-preset-rtl

+30 -11
+2 -1
test/unit/uno-preset-rtl.spec.ts
··· 1 1 import { afterEach, beforeEach, describe, expect, it, vi, type MockInstance } from 'vitest' 2 - import { presetRtl } from '../../uno-preset-rtl' 2 + import { presetRtl, resetRtlWarnings } from '../../uno-preset-rtl' 3 3 import { createGenerator } from 'unocss' 4 4 5 5 describe('uno-preset-rtl', () => { 6 6 let warnSpy: MockInstance 7 7 8 8 beforeEach(() => { 9 + resetRtlWarnings() 9 10 warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}) 10 11 }) 11 12
+28 -10
uno-preset-rtl.ts
··· 1 1 import type { CSSEntries, DynamicMatcher, Preset, RuleContext } from 'unocss' 2 2 import { cornerMap, directionSize, h } from '@unocss/preset-wind4/utils' 3 3 4 + // Track warnings to avoid duplicates 5 + const warnedClasses = new Set<string>() 6 + 7 + function warnOnce(message: string, key: string) { 8 + if (!warnedClasses.has(key)) { 9 + warnedClasses.add(key) 10 + // oxlint-disable-next-line no-console -- warn logging 11 + console.warn(message) 12 + } 13 + } 14 + 15 + /** Reset warning state (for testing) */ 16 + export function resetRtlWarnings() { 17 + warnedClasses.clear() 18 + } 19 + 4 20 const directionMap: Record<string, string[]> = { 5 21 'l': ['-left'], 6 22 'r': ['-right'], ··· 30 46 const defaultMap = { l: 'is', r: 'ie' } 31 47 const map = prefixMap || defaultMap 32 48 const replacement = map[direction as 'l' | 'r'] 33 - // oxlint-disable-next-line no-console -- warn logging 34 - console.warn( 49 + warnOnce( 35 50 `[RTL] Avoid using '${match}'. Use '${match.replace(direction === 'l' ? 'l' : 'r', replacement)}' instead.`, 51 + match, 36 52 ) 37 53 return matcher([match, replacement, size], context) 38 54 } ··· 83 99 ([, direction, size], context) => { 84 100 if (!size) return undefined 85 101 const replacement = direction === 'left' ? 'inset-is' : 'inset-ie' 86 - // oxlint-disable-next-line no-console -- warn logging 87 - console.warn( 102 + warnOnce( 88 103 `[RTL] Avoid using '${direction}-${size}'. Use '${replacement}-${size}' instead.`, 104 + `${direction}-${size}`, 89 105 ) 90 106 return directionSize('inset')(['', direction === 'left' ? 'is' : 'ie', size], context) 91 107 }, ··· 95 111 /^text-(left|right)$/, 96 112 ([, direction]) => { 97 113 const replacement = direction === 'left' ? 'start' : 'end' 98 - // oxlint-disable-next-line no-console -- warn logging 99 - console.warn(`[RTL] Avoid using 'text-${direction}'. Use 'text-${replacement}' instead.`) 114 + warnOnce( 115 + `[RTL] Avoid using 'text-${direction}'. Use 'text-${replacement}' instead.`, 116 + `text-${direction}`, 117 + ) 100 118 return { 'text-align': replacement } 101 119 }, 102 120 { autocomplete: 'text-(left|right)' }, ··· 112 130 } 113 131 const replacement = replacementMap[direction] 114 132 if (!replacement) return undefined 115 - // oxlint-disable-next-line no-console -- warn logging 116 - console.warn( 133 + warnOnce( 117 134 `[RTL] Avoid using 'rounded-${direction}'. Use 'rounded-${replacement}' instead.`, 135 + `rounded-${direction}`, 118 136 ) 119 137 return handlerRounded(['', replacement, size ?? 'DEFAULT'], context) 120 138 }, ··· 124 142 args => { 125 143 const [_, direction, size] = args 126 144 const replacement = direction === 'l' ? 'is' : 'ie' 127 - // oxlint-disable-next-line no-console -- warn logging 128 - console.warn( 145 + warnOnce( 129 146 `[RTL] Avoid using 'border-${direction}'. Use 'border-${replacement}' instead.`, 147 + `border-${direction}`, 130 148 ) 131 149 return handlerBorderSize(['', replacement, size || '1']) 132 150 },