Skip to main content

Module sfc_css

Module sfc_css 

Source
Expand description

Dead scoped-CSS class detection for Vue/Svelte single-file components.

A class defined in a <style scoped> block applies only to its own component’s markup (that is what scoped means), so a scoped class whose name appears nowhere else in the same SFC is a cleanup candidate. The “appears nowhere else” test is deliberately broad: any occurrence of the class name as a whole token anywhere outside the <style> blocks (a static class="...", a dynamic :class="{ name: x }" key, a class:name directive, or even a string in <script>) counts as a use. That keeps the signal conservative (it errs toward “used”), so it is reported as a candidate rather than a hard dead-code finding.

Functions§

scoped_unused_classes
Returns class names defined in <style scoped> blocks of an SFC that appear nowhere else in the component (cleanup candidates), sorted. Returns an empty vec when the source has no analyzable scoped block.
sfc_virtual_stylesheet
Build a “virtual stylesheet” from an SFC’s plain-CSS <style> blocks (any scoping). Each block body is placed at its real line in the SFC via blank-line padding, so CSS metric line numbers from compute_css_analytics map straight back onto the SFC. Returns None when the SFC has no plain-CSS <style> block (e.g. only lang="scss" blocks, which the CSS parser cannot read), so callers run the standard .css metric path on Vue/Svelte component styles.