Skip to content

Commit f1eebb8

Browse files
committed
Order list of linted files by frequency
Since it makes more sense for .rs files to appear at the top of the list of linted files and "other" files to appear at the end, this commit moves the "other" count outside of the `file_counts` dictionary and sorts the remaining "interesting" files by decreasing frequency.
1 parent 7884eb8 commit f1eebb8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/etc/tidy.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,22 @@ def do_license_check(name, contents):
6666
try:
6767
count_lines = 0
6868
count_non_blank_lines = 0
69+
count_other_linted_files = 0
6970

7071
interesting_files = ['.rs', '.py', '.js', '.sh', '.c', '.h']
7172

7273
file_counts = {ext: 0 for ext in interesting_files}
73-
file_counts['other'] = 0
7474

7575
def update_counts(current_name):
7676
global file_counts
77+
global count_other_linted_files
78+
7779
_, ext = os.path.splitext(current_name)
7880

79-
if ext in file_counts:
81+
if ext in interesting_files:
8082
file_counts[ext] += 1
8183
else:
82-
file_counts['other'] += 1
84+
count_other_linted_files += 1
8385

8486
all_paths = set()
8587

@@ -196,10 +198,11 @@ def interesting_file(f):
196198
report_err("UTF-8 decoding error " + str(e))
197199

198200
print
199-
for ext in file_counts:
200-
print "* linted " + str(file_counts[ext]) + " " + ext + " files"
201-
print "* total lines of code: " + str(count_lines)
202-
print "* total non-blank lines of code: " + str(count_non_blank_lines)
201+
for ext in sorted(file_counts, key=file_counts.get, reverse=True):
202+
print "* linted {} {} files".format(file_counts[ext], ext)
203+
print "* linted {} other files".format(count_other_linted_files)
204+
print "* total lines of code: {}".format(count_lines)
205+
print "* total non-blank lines of code: {}".format(count_non_blank_lines)
203206
print
204207

205208
sys.exit(err)

0 commit comments

Comments
 (0)