/alex-agent-skills:frontend-refactoringfrom alex-agent-skills
Use when the user wants to migrate templates to the new design system convention without breaking behavior or visuals. Examples: "Refactor this template", "Migrate this view to the new convention", "Clean up these class names", "Extract this pattern to a partial", "Replace repeated HTML with a loop"
Ships in alex-agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
!important. Fix selector scope, nesting, or cascade order instead. If a rule only works with !important, the refactor is not finished.@extend and @include first; then raw CSS declarations ordered by purpose: layout → sizing → spacing → typography → visual styling → motion and interaction; put nested selectors such as &:hover, &.is-active, and child elements last. If a declaration is unusual, place it in the closest matching group instead of inventing a one-off order.Gates are marked [GATE] — do not advance to the next step until the gate passes with zero failures.
0. Remove all !important — fix selector scope, nesting, or import order before touching anything else
[GATE] grep -rn '!important' must return no matches before continuing
1. Identify one repeating UI pattern (run `scan-partials.mjs` first)
2. Assess: can dynamic rendering reduce duplication? (hardcoded list → loop over data array)
3. Find all connected SCSS, JS, and vendor selectors referencing the old class names
4. Determine the correct replacement (native element → Bootstrap → semantic → new shared class)
5. Rename HTML classes and update SCSS selectors together
6. Remove legacy overlap so only one active source of truth remains
7. Safely merge equivalent CSS declarations when behavior will not change
8. Exhaust existing `@extend` and `@include` options first, then apply token variables and any remaining raw declarations
9. Run `prettify-scss.mjs` to automatically re-organize block order (directives → raw CSS → nested selectors)
10. Run `verify-conventions.mjs` to check structural and naming conventions
[GATE] verify-conventions.mjs must exit 0 before continuing — fix all FAIL lines first
11. Verify: visual, layout, and behavior are unchanged
12. Repeat for the next pattern
!importantBefore any refactoring begins, strip every !important from the SCSS files in scope.
grep -rn '!important' web/scss/overrides/
For each occurrence, fix the cascade instead:
base/, overrides/_fl-*, or pages/)web/scss/main.scss!important is not an allowed escape hatch in this repo.
Checklist:
!important in any SCSS file in scope[GATE]
grep -rn '!important' web/scss/overrides/must return no matches. Do not proceed to Step 1 until it is clean.
node skills/frontend-refactoring/scripts/scan-partials.mjs views/
Scan for:
aml-*, kyc-*, client-*)Pick one pattern. Do not attempt multiple in the same pass.
Checklist:
Convert repeated blocks to a loop when:
How:
$items = [...])Skip when: blocks differ structurally, or the items are semantically distinct (e.g. a 3-tab nav with unique behavior per tab).
Checklist:
grep -r "old-class-name" web/scss/
grep -r "old-class-name" web/js/
grep -n "\.vendor-selector" web/scss/vendor/_sb-admin-2.scss
A class may appear in multiple files, and a vendor-owned pattern may also have JS hooks tied to it. List them all before editing anything.
Checklist:
<button>, <nav>, <table>, <ul>) → use itbtn, badge, table, form-control) → use ititem, label, control) → reuse it/web/scss/overrides/If SB Admin 2 already owns the pattern:
!important, brittle specificity, or broad coupled behaviorChecklist:
.facelift-layout in /web/scss/overrides/_fl-*.scssIf the refactor intentionally replaces a vendor selector, remove the vendor class from the template instead of leaving both classes side by side.
Checklist:
aml-*, kyc-*, client-* class names used sparingly — prefer semantic names; text-align-* removedBefore simplifying declarations, remove the old competing selectors.
Check these locations explicitly:
web/scss/overrides/_additional.scssbase/_fl-*.scss filesThe goal is one source of truth per pattern. If both a vendor selector and a new semantic selector still style the same element, the refactor is not finished.
Checklist:
_additional.scss, old base files, or page-level SCSSAfter renaming selectors, simplify declarations only when the computed result stays the same.
Safe merges include cases like:
padding-top: 4px;
padding-right: 4px;
padding-bottom: 4px;
padding-left: 4px;
becoming:
padding: 4px;
Also merge other equivalent longhand sets into shorthand when all values and sides line up cleanly.
Do this only when:
Do not merge declarations when the shorthand could hide meaningful differences or change override behavior.
Checklist:
Before writing declarations for a selector block:
flex-row, px, py, transition, placeholders for @extend, etc.)@extend and @include lines firstMixins and shared-class directives outrank raw CSS. If a rule can be expressed with an existing @extend or @include, use that first.
Prefer patterns like:
@include flex-row(8px) instead of raw display, flex-direction, and gap@include px(16px) / @include py(8px) instead of raw padding declarations@include size(16px) instead of matching raw width and height@extend instead of repeating a known base patternPass raw px values on the allowed scale to spacing mixins (e.g. @include px(16px)). Do not use spacing variables (var(--spacing-*)).
Only leave a raw declaration in place when no existing @extend or @include expresses the same behavior cleanly.
Within a block, @extend and @include lines should be grouped at the top. Remaining raw CSS declarations come after them. Nested selectors must stay at the bottom of the block.
Priority order:
| Priority | Use | Instead of |
|---|---|---|
| 1st | Shared-class directive (@extend ...) | Repeating an existing base pattern in raw declarations |
| 2nd | Layout / behavior mixin (@include flex-row(8px), @include transition()) | display: flex; flex-direction: row; gap: 8px / transition: all 0.2s ease |
| 3rd | Spacing / size mixin (@include px(16px), @include py(8px), @include size(16px)) | Raw padding / margin / width / height declarations |
| 4th | Token variable (var(--stone-500), var(--text-sm)) | color: #6b7280; font-size: 0.875rem |
| Last resort | Raw px on the 4px scale | Only when no token or mixin exists |
Spacing values inside mixins should use raw px on the allowed scale (e.g. @include px(16px), not @include px(var(--spacing-4))). Spacing variables (var(--spacing-*)) are not required.
Available abstracts:
| File | What it provides |
|---|---|
web/scss/abstracts/_layout.scss | flex-row(gap?), flex-col(gap?), grid-cols(cols, gap?), flex-center, flex-between, transition(props?, duration?, easing?) |
web/scss/abstracts/_spacing.scss | p, m, px, py, mx, my, pt, pb, pl, pr, mt, mb, ml, mr, gap, gap-x, gap-y, size |
web/scss/abstracts/_variables.scss | Colors, brand tokens, shadows, radius, typography tokens |
web/scss/abstracts/_typography.scss | Font sizes, weights, line heights |
web/scss/abstracts/_radius.scss | Border-radius values |
web/scss/abstracts/_shadow.scss | Box-shadow values |
Gap scale: 4px, 8px, 10px, 12px, 16px, 20px, 24px, 32px, 40px, 48px. Normalize to the nearest step only when the difference is 1px or less; otherwise keep the original value. 10px is the only non-4x value.
Checklist:
@extend and @include options exhausted before writing raw CSS@include flex-row, flex-col, grid-cols)@include px, py, p, etc.) with raw px values on the allowed scale& for pseudo-classes, states, and modifiersDo not manually reorder declarations. Run the script and let it enforce block order automatically:
node skills/frontend-refactoring/scripts/prettify-scss.mjs web/scss/overrides/_fl-component.scss
The script re-organizes every selector block in-place to the required order:
@extend and @include lines firstIt also reports any structural issues it cannot fix automatically (e.g. flat selectors that must be nested, declarations exceeding max depth). Fix all reported FAIL lines before moving on.
After the script runs, review the diff to confirm no declarations were dropped or reordered in a way that changes computed output.
Checklist:
prettify-scss.mjs exits 0 — zero FAIL lines reported@extend/@include → raw CSS → nested selectors[GATE]
prettify-scss.mjsmust exit 0 before running Step 10.
# SCSS only
node skills/frontend-refactoring/scripts/lint-scss.mjs web/scss/overrides/_fl-component.scss
# SCSS + template
node skills/frontend-refactoring/scripts/verify-conventions.mjs \
web/scss/overrides/_fl-component.scss views/path/to/template.php
verify-conventions.mjs additionally checks: .facelift-layout wrapper, flat selectors, nesting depth, component-scoped class remnants, inline styles, appearance-based class names.
Both lint-scss.mjs and verify-conventions.mjs fail on any !important. Do not waive that check.
Fix all FAIL lines. WARN lines are advisory.
Checklist:
verify-conventions.mjs exits 0 — zero FAIL lines[GATE]
verify-conventions.mjsmust exit 0 before proceeding to Step 11.
| Check | How |
|---|---|
| Visual | Load the page — identical spacing, colors, typography, borders? |
| Layout | Resize viewport — responsive behavior holds? |
| Behavior | Clicks, hovers, form submissions, JS states work? |
Stop and revert if anything changed.
Checklist:
Priority order for next pattern:
text-align-center → text-center)<nav>, <ul>, <table>, <button>)Checklist:
Extract a block when:
Process: Extract to a partial (e.g. _status-badge.php) → parameterize only what varies → replace inline copies → verify each call site.
Each step has its own checklist inline above. The two hard gates that block further progress are:
| Gate | Script | Required outcome |
|---|---|---|
| After Step 9 | prettify-scss.mjs | exit 0 — zero FAIL lines |
| After Step 10 | verify-conventions.mjs | exit 0 — zero FAIL lines |
Do not mark a pattern done unless all per-step checklists are ticked and both gate scripts exit 0.
What SKILL.md sets; muted values are Claude Code's defaults
33 skills in this plugin
/basecampInteract with Basecamp via the Basecamp CLI. Full API coverage: projects, todos, cards,
messages, files, schedule, check-ins, timeline, recordings, templates, webhooks,
subscriptions, lineup, and campfire. Use for ANY Basecamp question or action.
/cert-tutorAct as a personal tutor for professional certification exams (AWS, Azure, GCP, Kubernetes, security, PMP, and similar). Use whenever the user is studying for a cert - explaining an exam topic or service, quizzing with exam-style scenario questions, reviewing missed questions, running a timed mock exam, or asking "which service for X" or "is this the right answer". Trigger even for a single question, and even if the user never says "teach me", e.g. "difference between Kendra and OpenSearch", "quiz me on IAM", "why is B wrong here"./Other plugins' skills for the same job
npx claudepluginhub duyphaphach/agent-skills --plugin alex-agent-skills