RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

rails-css_unused v0.2.1 — Find unused CSS classes in Rails apps, with smart dynamic

rails-css_unused is a static analysis gem that scans your stylesheets and all view files to report CSS classes that are defined but never used — no server required, no browser, pure file scanning.

bash bundle exec rake css_unused:report

v0.2.1 adds smart dynamic class variable detection — solving the most common false-positive in Rails apps where classes are assigned to a variable and rendered via ERB interpolation:

erb <% status_class = exam.approved? ? "status-approved" : "status-draft" %> <span class="<%= status_class %>">

The fix exploits a Ruby language rule: variable names cannot contain hyphens, so any hyphenated quoted string is unambiguously a string value. The scanner now extracts these automatically with no configuration needed.

Supports: ERB, HAML, Slim, ViewComponent, Phlex, Stimulus JS, BEM, CI exit codes.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in