Add experimental unused CSS checker - #34
Conversation
Scan first-party stylesheets during Thim compilation and report classes that never appear in templates, Kotlin/Java, or first-party JS. Prefix matches cover interpolated names. Vendor CSS is ignored. The default is warn-and-report; failOnUnusedCss turns unused classes into a build error.
Read backtick strings, nested quotes inside interpolations, and the last class token before $ so short prefixes like r-is- and r-mchart- count as used.
|
Follow-up scan after teaching the checker JS backticks, nested quotes in `${}`, and last-token prefixes such as `r-is-` / `r-mchart-`. Utin ( Eteo admin: 27 defined, 27 used, 0 unused. Eteo web-app: 223 defined, 189 used, 34 unused leftover landing/signup rules. Cleanup PR opened separately. ReAI still has the one unused class (`r-max-md:r-font-size-l`); cleanup PR opened separately. `failOnUnusedCss` stays off until apps list every shared usage root. |
|
Superseded by #46. The released implementation uses one cacheable application-wide root task, discovers production usage across all Gradle modules automatically, participates in |
Why
We want unused first-party CSS to fail the build, the same way unused messages already can. Before flipping that switch, the compiler needs a conservative checker we can run against ReAI and inspect for false positives.
What
.cssundersrc/main/resources/static(skipsvendor/)class/th:class, Kotlin/Java/JS string literalsr-analytics-sparkline-bar-$indexhtmx-request/htmx-indicatoras runtime-appliedbuild/reports/thim/css.jsonand warns;failOnUnusedCss.set(true)fails the buildcssUsage.from(...)lists extra modules that share the stylesheet./gradlew :compiler:cssCheck --args='--css=... --usage=...'ReAI result
Against web-app CSS plus usage from
web-app,enak, andtimesheet:r-max-md:r-font-size-l(only exists inbase.css, never referenced)Scanning only
web-applooked like 25 unused classes; 22 of those were live in Enak templates. Two more lived intimesheet. The remaining one is real dead CSS.failOnUnusedCssstays off until consuming apps list every shared usage root.