Skip to content

Instantly share code, notes, and snippets.

@fredkingham
Last active December 25, 2015 06:39
@task
def grep_for_classes():
"""
cheap and dirty fabric grep for all sass files that have classes that aren't used and prints them out,
disclaimers:
only does classes not other ides
only prints out unused classes doesn't delete them
I haven't found anywhere it breaks but I'm not going to guarentee it
"""
command = "grep -r -P --no-filename --only-matching --include *.scss '[\s\n]\.[a-zA-Z][0-9a-zA-Z\-]*' *"
classes = local(command, capture=True).split("\n")
classes = set([valid_class.strip().lstrip(".") for valid_class in classes if valid_class])
grep_com = "grep -r -P --no-filename --only-matching --include *.html 'class=\"([\w-]*\s)*%s([\w-]*\s)*\"' *"
not_found = []
with quiet():
for valid_class in classes:
found = local(grep_com % valid_class, capture=True)
if not found:
not_found.append(valid_class)
print "consider removing"
for i in not_found:
print i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment