Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(rules): ban Tailwind class-string constants in TSX (FE-30) (#5857)

teobc5f5a8283a9
diff --git a/docs/STYLE_GUIDE.md b/docs/STYLE_GUIDE.md
index ddb706ae6a..2837d7cd67 100644
--- a/docs/STYLE_GUIDE.md
+++ b/docs/STYLE_GUIDE.md
@@ -236,3 +236,8 @@ TypeScript · `[ui]` UI / UX conventions
If none exists below the app root, or the nearest one is far outside the component's
own UI scope (e.g. the route-level boundary in `apps/web/src/routes/Root.tsx`, whose
fallback blanks unrelated UI), flag it and ask which boundary is intended.
+- **FE-30** `[ui]` Never hoist Tailwind class strings into named constants
+ (`const DAY_CELL_CLASS = '...'`) — shared markup+styling is a component; a class
+ string can't carry structure, props, or behavior. Extract a component, or inline the
+ literal at its single use; styling variants are component props, not exported
+ strings. (enforced: ast-grep `tsx-no-class-string-consts`, warning)
diff --git a/rules/ast-grep/tsx-no-class-string-consts.yml b/rules/ast-grep/tsx-no-class-string-consts.yml
new file mode 100644
index 0000000000..936cd7bc0d
--- /dev/null
+++ b/rules/ast-grep/tsx-no-class-string-consts.yml
@@ -0,0 +1,29 @@
+id: tsx-no-class-string-consts
+language: tsx
+severity: warning
+message: Don't hoist Tailwind class strings into named constants — shared markup+styling is a component, not a string.
+note: |-
+ Rule FE-30 in docs/STYLE_GUIDE.md. A named class-string constant
+ (`const DAY_CELL_CLASS = 'aspect-square w-full shrink-0'`) is a
+ component's render detail leaking into module scope: it can't carry
+ structure, props, or behavior, and every consumer re-implements the
+ element around it. Extract a component (or keep the literal inline at
+ its single use). For genuine styling variants, use the component's
+ props, not exported strings. When a class string must feed an imperative
+ DOM/editor API and no component boundary exists, inline it at the call
+ site. ~46 legacy uses exist — don't add new ones.
+files:
+ - apps/web/**
+ - packages/**
+rule:
+ kind: variable_declarator
+ all:
+ - has:
+ field: name
+ kind: identifier
+ regex: (?i)class(es|_?names?)?$
+ - has:
+ field: value
+ any:
+ - kind: string
+ - kind: template_string