From 50d840aceab7afffc7dcbf9732e8d65a7cadb459 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Thu, 11 Jan 2018 10:20:37 -0500 Subject: [PATCH] Lint: inflect for pluralizing --- tools/lint/lint.py | 29 +++++++++++++++-------------- tools/lint/requirements.txt | 1 + 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/tools/lint/lint.py b/tools/lint/lint.py index 92ccec5abd..979616a585 100755 --- a/tools/lint/lint.py +++ b/tools/lint/lint.py @@ -3,10 +3,13 @@ # This code is governed by the BSD license found in the LICENSE file. import argparse -import sys +import inflect +import os import pip import pip.req +import sys +ie = inflect.engine() try: __import__('yaml') @@ -42,13 +45,13 @@ parser.add_argument('path', help='file name or directory of files to lint') checks = [ - CheckEsid(), - CheckFrontmatter(), - CheckFeatures('features.txt'), - CheckHarnessFeatures(), - CheckLicense(), - CheckNegative() - ] + CheckEsid(), + CheckFrontmatter(), + CheckFeatures('features.txt'), + CheckHarnessFeatures(), + CheckLicense(), + CheckNegative() +] def lint(file_names): errors = dict() @@ -76,7 +79,7 @@ if __name__ == '__main__': files = [path for _path in args.path for path in collect_files(_path)] file_count = len(files) - print 'Linting %s file%s.' % (file_count, 's' if file_count != 1 else '') + print 'Linting %s %s' % (file_count, ie.plural('file', file_count)) all_errors = lint(files) unexpected_errors = dict(all_errors) @@ -88,15 +91,13 @@ if __name__ == '__main__': del unexpected_errors[file_name] error_count = len(unexpected_errors) - s = 's' if error_count != 1 else '' - - print 'Linting complete. %s error%s found.' % (error_count, s) + print 'Linting complete. %s %s found.' % (error_count, ie.plural('error', error_count)) if error_count == 0: sys.exit(0) - for file_name, failures in unexpected_errors.iteritems(): + for file_name, failures in iter(sorted(unexpected_errors.iteritems())): for ID, message in failures.iteritems(): - eprint('%s: %s - %s' % (file_name, ID, message)) + eprint('%s: %s - %s' % (os.path.abspath(file_name), ID, message)) sys.exit(1) diff --git a/tools/lint/requirements.txt b/tools/lint/requirements.txt index efb082d8de..8ad7322903 100644 --- a/tools/lint/requirements.txt +++ b/tools/lint/requirements.txt @@ -1 +1,2 @@ PyYAML==3.11 +inflect==0.2.5