-
Notifications
You must be signed in to change notification settings - Fork 0
chore: enforce ui-kit styling through the uno preset — ban per-component .css at three layers #464
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
Closed
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # Blocks Claude Code Write/Edit/MultiEdit calls that would create or modify a | ||
| # per-component .css file under a ui-kit package's src/, per the repo rule: | ||
| # component styling goes through packages/uno-preset, .css is only for | ||
| # tokens.css and theme/ sheets. Mirrors scripts/check-ui-kit-css.ts's | ||
| # pattern/allowlist so the three enforcement layers (this hook, prek, CI) | ||
| # agree on exactly one definition of "banned path". | ||
| # | ||
| # Same stdin JSON contract as turbo-filter-gate.sh: a PreToolUse hook reads | ||
| # the tool call as JSON on stdin and blocks by exiting 2 with a stderr | ||
| # message. Anything unparseable fails open. | ||
|
|
||
| if ! command -v jq >/dev/null 2>&1; then | ||
| echo "ui-kit-css-gate: jq not on PATH, skipping check." >&2 | ||
| exit 0 | ||
| fi | ||
|
|
||
| INPUT="$(cat)" | ||
| FILE_PATH="$(jq -r '.tool_input.file_path // empty' <<<"$INPUT" 2>/dev/null || true)" | ||
|
|
||
| [ -n "$FILE_PATH" ] || exit 0 | ||
|
|
||
| NORMALIZED="$FILE_PATH" | ||
| while printf '%s\n' "$NORMALIZED" | grep -Eq '(^|/)[^/]+/\.\.(/|$)|(^|/)\.(/|$)'; do | ||
| NORMALIZED="$(printf '%s\n' "$NORMALIZED" | sed -E 's#(^|/)[^/]+/\.\.(/|$)#\1#; s#(^|/)\.(/|$)#\1#; s#//#/#g')" | ||
| done | ||
|
|
||
| printf '%s\n' "$NORMALIZED" | grep -Eq '(^|/)packages/ui-kit-[^/]+/src/.*\.css$' || exit 0 | ||
|
|
||
| BASENAME="$(basename "$NORMALIZED")" | ||
| if [ "$BASENAME" = "tokens.css" ]; then | ||
| exit 0 | ||
| fi | ||
| if printf '%s\n' "$NORMALIZED" | grep -Eq '(^|/)theme/'; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| { | ||
| echo "ui-kit-css-gate: BLOCKED: $FILE_PATH is a banned per-component ui-kit .css file." | ||
| echo | ||
| echo "component styles belong in packages/uno-preset (keyframes -> src/animation.ts, animation" | ||
| echo "shortcuts -> src/motion.ts, effects/rules/preflights -> the preset), .css is only for" | ||
| echo "tokens/themes." | ||
| } >&2 | ||
|
|
||
| exit 2 |
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,44 @@ | ||
| #!/usr/bin/env node | ||
| import {execFileSync} from 'node:child_process' | ||
| import {posix} from 'node:path' | ||
|
|
||
| const UI_KIT_CSS_PATTERN = /^packages\/ui-kit-[^/]+\/src\/.*\.css$/ | ||
| const GIT_SCAN_PATHSPEC = ':(glob)packages/ui-kit-*/src/**/*.css' | ||
|
|
||
| const MESSAGE = | ||
| 'component styles belong in packages/uno-preset (keyframes -> src/animation.ts, animation ' + | ||
| 'shortcuts -> src/motion.ts, effects/rules/preflights -> the preset), .css is only for ' + | ||
| 'tokens/themes.' | ||
|
|
||
| function isAllowlisted(path: string): boolean { | ||
| const segments = path.split('/') | ||
| const basename = segments[segments.length - 1] | ||
| if (basename === 'tokens.css') return true | ||
| return segments.includes('theme') | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| function findBannedPaths(paths: string[]): string[] { | ||
| return paths | ||
| .map((path) => posix.normalize(path.replaceAll('\\', '/'))) | ||
| .filter((path) => UI_KIT_CSS_PATTERN.test(path) && !isAllowlisted(path)) | ||
| } | ||
|
|
||
| function scanTrackedFiles(): string[] { | ||
| const output = execFileSync('git', ['ls-files', GIT_SCAN_PATHSPEC], {encoding: 'utf8'}) | ||
| return output.split('\n').filter((line) => line.length > 0) | ||
| } | ||
|
|
||
| function main(): void { | ||
| const argPaths = process.argv.slice(2) | ||
| const candidatePaths = argPaths.length > 0 ? argPaths : scanTrackedFiles() | ||
| const banned = findBannedPaths(candidatePaths) | ||
|
|
||
| if (banned.length === 0) return | ||
|
|
||
| console.error('check-ui-kit-css: banned ui-kit component .css file(s) found:\n') | ||
| for (const path of banned) console.error(` ${path}`) | ||
| console.error(`\n${MESSAGE}`) | ||
| process.exitCode = 1 | ||
| } | ||
|
|
||
| main() | ||
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.