Skip to content

Instantly share code, notes, and snippets.

@Masa331
Last active June 6, 2020 15:47
Show Gist options
  • Save Masa331/6ccb123f9cb85765c9cbd9b16135a976 to your computer and use it in GitHub Desktop.
Save Masa331/6ccb123f9cb85765c9cbd9b16135a976 to your computer and use it in GitHub Desktop.
Find unused css
css = File.read 'app/assets/stylesheets/new_web/app.css'
classes = css.scan /(?<=\.)[a-z][\w_-]+/
code = Dir.glob('app/views/static_pages/*').unshift 'app/views/layouts/new_web.html.erb'
code = code + Dir.glob('app/assets/javascripts/new_web/*')
markups = code.map { File.read _1 }
unused = classes.select do |css_class|
markups.none? { _1.include? css_class }
end.uniq
unused.each { p _1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment