Created
February 25, 2009 17:44
-
-
Save llimllib/70312 to your computer and use it in GitHub Desktop.
run with "python as3_unused_imports.py <directory to search recursively>"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys, re | |
from os import walk | |
from os.path import join as pathjoin | |
from pprint import pprint as pp | |
def parsef(f): | |
imports = [] | |
notimports = [] | |
for line in file(f): | |
r = re.search("^\s*import\s*(.*)\s*;\s*$", line) | |
if r: imports.append(r.groups()[0]) | |
else: notimports.append(line) | |
return imports, notimports | |
#be super conservative and don't list any imports whose name is mentioned anywhere in the file | |
def find_unused(notimports, imports): | |
return [i for i in imports if "".join(notimports).find(i) == -1] | |
root = sys.argv[-1] | |
for dirpath, dirnames, filenames in walk(root): | |
for f in (f_ for f_ in filenames if f_.endswith(".as")): | |
f = pathjoin(dirpath, f) | |
imports, notimports = parsef(f) | |
classnames = [x[x.rfind(".")+1:] for x in imports] | |
unused = find_unused(notimports, classnames) | |
if unused: | |
print f + " :" | |
pp(unused) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment