-
-
Notifications
You must be signed in to change notification settings - Fork 432
test: configure lint-css to check a11y and rtl #1203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import type { Preset } from 'unocss' | ||
|
|
||
| export type CollectorChecker = (warning: string, rule: string) => void | ||
|
|
||
| // Track warnings to avoid duplicates | ||
| const warnedClasses = new Set<string>() | ||
|
|
||
| function warnOnce(message: string, key: string) { | ||
| if (!warnedClasses.has(key)) { | ||
| warnedClasses.add(key) | ||
| // oxlint-disable-next-line no-console -- warn logging | ||
| console.warn(message) | ||
| } | ||
| } | ||
|
|
||
| /** Reset warning state (for testing) */ | ||
| export function resetA11yWarnings() { | ||
| warnedClasses.clear() | ||
| } | ||
|
|
||
| const textPxToClass: Record<number, string> = { | ||
| 11: 'text-2xs', | ||
| 10: 'text-3xs', | ||
| 9: 'text-4xs', | ||
| 8: 'text-5xs', | ||
| } | ||
|
|
||
| function reportTextSizeWarning(match: string, suggestion: string, checker?: CollectorChecker) { | ||
| const message = `[A11y] Avoid using '${match}', ${suggestion}.` | ||
| if (checker) { | ||
| checker(message, match) | ||
| } else { | ||
| warnOnce(message, match) | ||
| } | ||
| } | ||
|
|
||
| export function presetA11y(checker?: CollectorChecker): Preset { | ||
| return { | ||
| name: 'a11y-preset', | ||
| // text-[N] (arbitrary where N is a size in px or em): recommend text-2xs/text-3xs/text-4xs/text-5xs or "use classes" | ||
| rules: [ | ||
| [ | ||
| /^text-\[(\d+(\.\d+)?)(px)?\]$/, | ||
| ([match, numStr], context) => { | ||
| const num = Number(numStr) | ||
| const fullClass = context.rawSelector || match | ||
| const suggestedClass = textPxToClass[num] | ||
| if (suggestedClass) { | ||
| reportTextSizeWarning(fullClass, `use '${suggestedClass}' instead`, checker) | ||
| } else { | ||
| reportTextSizeWarning( | ||
| fullClass, | ||
| 'use text-<size> classes or rem values instead of custom values', | ||
| checker, | ||
| ) | ||
| } | ||
| return [['font-size', `${num}px`]] | ||
| }, | ||
| { autocomplete: 'text-[<num>]' }, | ||
| ], | ||
| [ | ||
| /^text-\[(\d+(\.\d+)?)em\]$/, | ||
| ([match, numStr], context) => { | ||
| const num = Number(numStr) | ||
| const fullClass = context.rawSelector || match | ||
| reportTextSizeWarning( | ||
| fullClass, | ||
| 'use text-<size> classes or rem values instead of custom values', | ||
| checker, | ||
| ) | ||
| return [['font-size', `${num}em`]] | ||
| }, | ||
| { autocomplete: 'text-[<num>]em' }, | ||
| ], | ||
| ], | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.