CI & Build / Python lint (push) Failing after 3s
CI & Build / Plugin hooks (push) Successful in 9s
CI & Build / TypeScript typecheck (push) Successful in 23s
CI & Build / integration (push) Successful in 27s
CI & Build / Python tests (push) Canceled after 38s
CI & Build / Build & push image (push) Canceled after 0s
Operator reported four things looking wrong. Two were the same bug, and it is
not a design drift — it is deleted CSS.
Removing a rule from a scoped stylesheet leaves its modifiers behind. The
selector still exists, so nothing reads as unused, and the element renders with
no base styling at all:
.btn-workspace base gone, :hover survived — the Workspace link rendered
as raw browser blue, underlined
.milestone-header base gone, .clickable and :hover survived. Every child is
written for a flex ROW (.ms-name { flex: 1 }, the progress
track, .ms-pct), so without the parent they stacked and a
one-line milestone became five. That is the "projects
section uses space poorly" — a deletion, not a redesign.
.milestone-group no rule at all; the card around each milestone
.ds-header only its h1 descendant survived
vue-tsc cannot see any of it. A dead style typechecks perfectly.
scripts/check_dangling_styles.py finds the shape: an element whose every static
class has no base rule anywhere, while at least one carries modifier rules. It
reports 11 more. Reported and not gated, because a genuinely bare wrapper is
legitimate — the signal is the count growing. Runs in the lint lane, stdlib
only, and knows no class name or convention (rule #115).
Also from the same report:
- The header pill bar was `position: absolute; left: 50%`, so it did not
participate in layout: out of room, it OVERLAPPED the brand and the utility
cluster instead of pushing them. A sixth link reached that at ~1270px, an
ordinary window. Now `1fr auto 1fr` — a 1fr track has an auto minimum, so
neither side can be squeezed under its content and the two stay equal, which
is what keeps the bar centred in the viewport rather than in the leftover
space. Overflow becomes the header growing, not two things sharing pixels.
- The token preview put its checkerboard on the whole specimen stage, so every
swatch sat in a frame of checks and the pattern read as the loudest thing on
the page. The checks now sit UNDER the colour as a second background layer:
an opaque value hides them, a 15% tint shows exactly as much as it should.
Text-bearing specimens lose the box entirely, and name/value/purpose are one
line each with the full text on hover — they wrapped freely before, so a card
was two lines tall or five depending on how long its color-mix() happened to
be, and the grid had no rhythm.
- .btn-cta joins the shared button family: the gradient-and-glow brand moment
the system carries tokens for, which had been living in one view's scoped
block. That is what made it deletable. The header actions are now one size
and one family instead of four sizes and two.
- The shared button shape gained inline-flex + gap, so a button carrying an
icon centres it without each caller rebuilding the row.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UaYUaouG9jjhATyuxCKrQs
157 lines
5.7 KiB
Python
157 lines
5.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Find elements whose classes have no base rule — the dangling-selector bug.
|
|
|
|
THE FAILURE THIS CATCHES
|
|
|
|
Deleting a CSS rule from a scoped stylesheet is not the local edit it looks
|
|
like. Three ways it goes wrong, all of them silent:
|
|
|
|
1. A rule is deleted and its `:hover` / modifier survives. The selector still
|
|
exists, so nothing reads as unused, but the element renders with no base
|
|
styling at all. `.btn-workspace:hover` outlived `.btn-workspace` and a
|
|
router-link rendered as raw browser blue for days.
|
|
|
|
2. The parent's layout rule is deleted while the children keep theirs.
|
|
`.milestone-header` was a flex row; its children still declare `flex: 1`
|
|
and `flex-shrink: 0`. Without the parent they stack vertically, and a
|
|
milestone that was one line becomes five. Nothing errors — the page just
|
|
wastes space, which reads as a design decision.
|
|
|
|
3. A rule is removed from a comma-separated group, leaving `.a,` dangling in
|
|
front of the next rule and swallowing it. That one at least has a
|
|
brace-balance tell; these two do not.
|
|
|
|
None of it is visible to `vue-tsc`, which is the frontend's entire check. A
|
|
dead style typechecks perfectly.
|
|
|
|
WHAT IT REPORTS
|
|
|
|
An element whose every static class is styled NOWHERE as a base rule, while at
|
|
least one of them appears in the file's CSS. That conjunction is the signal: a
|
|
class nobody styles is ordinary (a hook for a test, a semantic label), and a
|
|
class with only modifier rules is a deletion that went half-way.
|
|
|
|
Descendant selectors count as a base — `.panel .row {}` styles `.row` — because
|
|
from the element's side there is no difference. Only the LAST compound of a
|
|
selector is what it styles.
|
|
|
|
REPORT, NOT FAIL. Bare wrappers with no styling of their own are legitimate,
|
|
so this cannot be a gate without a suppression mechanism nobody would maintain.
|
|
A count that grows is the signal to look.
|
|
|
|
INSTANCE-AGNOSTIC (rule #115). Nothing here knows a class name, a component, or
|
|
a convention; point it at any Vue tree.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import pathlib
|
|
import re
|
|
import sys
|
|
|
|
STYLE_BLOCK = re.compile(r"<style[^>]*>(.*?)</style>", re.S)
|
|
CSS_COMMENT = re.compile(r"/\*.*?\*/", re.S)
|
|
# `class="a b"` only — never `:class="[...]"`, whose value is an expression.
|
|
# The negative lookbehind is the whole point: a bound class list mentions names
|
|
# that a static parse would misread as the element's only classes.
|
|
STATIC_CLASS = re.compile(r'(?<![:\w-])class="([^"{}\[\]]*)"')
|
|
SELECTOR = re.compile(r"([^{}]+)\{")
|
|
CLASS_TOKEN = re.compile(r"\.([A-Za-z][\w-]*)")
|
|
BARE_CLASS = re.compile(r"\.([\w-]+)\Z")
|
|
|
|
|
|
def shared_classes(sheets: list[pathlib.Path]) -> set[str]:
|
|
"""Class names any global stylesheet defines — a base rule from elsewhere."""
|
|
names: set[str] = set()
|
|
for sheet in sheets:
|
|
if sheet.exists():
|
|
names |= set(CLASS_TOKEN.findall(sheet.read_text()))
|
|
return names
|
|
|
|
|
|
def based_classes(css: str) -> set[str]:
|
|
"""Classes this stylesheet gives a base rule to.
|
|
|
|
The last compound of a selector is what the rule styles: in
|
|
`.panel .row:hover` that is `.row:hover`, a modifier — but in `.panel .row`
|
|
it is `.row`, a base. So a selector qualifies only when its final compound
|
|
is a lone class with nothing appended.
|
|
"""
|
|
out: set[str] = set()
|
|
for selector in SELECTOR.findall(css):
|
|
for part in selector.split(","):
|
|
part = part.strip()
|
|
if not part or part.startswith("@"):
|
|
continue
|
|
last = re.split(r"[\s>+~]+", part)[-1]
|
|
match = BARE_CLASS.fullmatch(last)
|
|
if match:
|
|
out.add(match.group(1))
|
|
return out
|
|
|
|
|
|
def scan(path: pathlib.Path, shared: set[str]) -> list[tuple[str, list[str]]]:
|
|
source = path.read_text()
|
|
template = source.split("<style")[0]
|
|
css = "\n".join(CSS_COMMENT.sub("", block) for block in STYLE_BLOCK.findall(source))
|
|
if not css.strip():
|
|
return []
|
|
|
|
based = based_classes(css)
|
|
mentioned = set(CLASS_TOKEN.findall(css))
|
|
|
|
findings: list[tuple[str, list[str]]] = []
|
|
for attr in sorted(set(STATIC_CLASS.findall(template))):
|
|
names = [n for n in attr.split() if re.fullmatch(r"[A-Za-z][\w-]*", n)]
|
|
if not names:
|
|
continue
|
|
if any(n in based or n in shared for n in names):
|
|
continue
|
|
dangling = [n for n in names if n in mentioned]
|
|
if dangling:
|
|
findings.append((attr, dangling))
|
|
return findings
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--root", default="frontend/src", help="tree of .vue files")
|
|
parser.add_argument(
|
|
"--shared",
|
|
action="append",
|
|
default=None,
|
|
help="global stylesheet whose classes count as a base rule (repeatable)",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
root = pathlib.Path(args.root)
|
|
if not root.exists():
|
|
print(f"{root}: no such directory", file=sys.stderr)
|
|
return 2
|
|
|
|
sheets = [pathlib.Path(s) for s in (args.shared or [])]
|
|
if not sheets:
|
|
sheets = sorted(root.glob("assets/*.css"))
|
|
shared = shared_classes(sheets)
|
|
|
|
total = 0
|
|
for path in sorted(root.rglob("*.vue")):
|
|
for attr, dangling in scan(path, shared):
|
|
total += 1
|
|
print(f'{path}: class="{attr}" — styled but never based: {", ".join(dangling)}')
|
|
|
|
print()
|
|
if total:
|
|
print(
|
|
f"REPORT: {total} element(s) whose classes carry modifier rules but no base "
|
|
f"rule. Each is either a deleted rule that left its :hover behind, or a "
|
|
f"deliberately bare wrapper."
|
|
)
|
|
else:
|
|
print("OK — every styled class has a base rule.")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|