Skip to main content

declarations_by_class

Function declarations_by_class 

Source
pub fn declarations_by_class(css: &str) -> BTreeMap<String, BTreeSet<String>>
Expand description

The class names a stylesheet’s selectors match.

Public because the check this exists for reads an app’s stylesheet too, and comparing what makeover defines against what the app defines is only meaningful if both sides were read the same way.

Selector text only. A declaration value can hold a dot (0.5rem, transition: .2s) and none of those are classes, so the scan tracks whether it is inside a declaration block and ignores what it finds there. An at-rule block (@layer, @media, @supports) contains rules rather than declarations, which is why a depth counter alone is not enough: the stack records what kind of block each brace opened. Which properties a stylesheet sets on each class it names.

The grain a drift check actually wants. A class name in common is not by itself a divergence: goingson’s .badge sets shape and the generated .badge sets fill and edge, and the app’s own comment says “do not add background, border or box-shadow here”. That arrangement is settled and correct, so a check that flagged the shared name would demand deleting it. A shared property is the thing that goes wrong, because app CSS is unlayered and takes the property from the design system silently.

A property appearing under more than one selector arm collapses into one entry. That loses a real distinction – the sort caret’s reserved gap is content on the unsorted arm and the generated caret is content on the sorted one, which is a deliberate pairing rather than a clash – so a consumer of this needs a way to say a pair was reviewed. Deciding that here would need a selector matcher, and a check that guesses wrong about specificity fails correct builds.