linter: Replace --pep8 with new --frontend/--backend options.

Adds the --frontend and --backend options to replace
--pep8.

Significantly modified by tabbott to use a cleaner framework.
This commit is contained in:
Robert Hönig 2017-08-25 15:23:02 +02:00 committed by Tim Abbott
parent 2186d53cf5
commit c5da0ada31
4 changed files with 25 additions and 15 deletions

View File

@ -47,9 +47,6 @@ def run():
parser.add_argument('--full', parser.add_argument('--full',
action='store_true', action='store_true',
help='Check some things we typically ignore') help='Check some things we typically ignore')
parser.add_argument('--pep8',
action='store_true',
help='Run the pep8 checker')
parser.add_argument('--no-gitlint', parser.add_argument('--no-gitlint',
action='store_true', action='store_true',
help='Disable gitlint') help='Disable gitlint')
@ -62,6 +59,13 @@ def run():
parser.add_argument('targets', parser.add_argument('targets',
nargs='*', nargs='*',
help='Specify directories to check') help='Specify directories to check')
limited_tests_group = parser.add_mutually_exclusive_group()
limited_tests_group.add_argument('--frontend',
action='store_true',
help='Only check files relevant to frontend')
limited_tests_group.add_argument('--backend',
action='store_true',
help='Only check files relevant to backend')
args = parser.parse_args() args = parser.parse_args()
tools_dir = os.path.dirname(os.path.abspath(__file__)) tools_dir = os.path.dirname(os.path.abspath(__file__))
@ -86,10 +90,17 @@ def run():
print('If you really know what you are doing, use --force to run anyway.') print('If you really know what you are doing, use --force to run anyway.')
sys.exit(1) sys.exit(1)
backend_file_types = ['py', 'sh', 'pp', 'json', 'md', 'txt', 'text', 'yaml']
frontend_file_types = ['js', 'css', 'handlebars', 'html']
file_types = backend_file_types + frontend_file_types
if args.backend:
file_types = backend_file_types
if args.frontend:
file_types = frontend_file_types
by_lang = cast(Dict[str, List[str]], by_lang = cast(Dict[str, List[str]],
lister.list_files(args.targets, modified_only=args.modified, lister.list_files(args.targets, modified_only=args.modified,
ftypes=['py', 'sh', 'js', 'pp', 'css', 'handlebars', ftypes=file_types,
'html', 'json', 'md', 'txt', 'text', 'yaml'],
use_shebang=True, group_by_ftype=True, exclude=EXCLUDED_FILES)) use_shebang=True, group_by_ftype=True, exclude=EXCLUDED_FILES))
# Invoke the appropriate lint checker for each language, # Invoke the appropriate lint checker for each language,
@ -178,12 +189,11 @@ def run():
failed = check_pyflakes(args, by_lang) failed = check_pyflakes(args, by_lang)
return 1 if failed else 0 return 1 if failed else 0
if args.pep8: @lint
@lint def pep8():
def pep8(): # type: () -> int
# type: () -> int failed = check_pep8(by_lang['py'])
failed = check_pep8(by_lang['py']) return 1 if failed else 0
return 1 if failed else 0
failed = run_parallel(lint_functions) failed = run_parallel(lint_functions)

View File

@ -16,10 +16,10 @@ if [ -z "$changed_files" ]; then
fi fi
if [ -z "$VIRTUAL_ENV" ] && `which vagrant > /dev/null` && [ -e .vagrant ]; then if [ -z "$VIRTUAL_ENV" ] && `which vagrant > /dev/null` && [ -e .vagrant ]; then
vcmd="/srv/zulip/tools/lint --pep8 --no-gitlint --force $changed_files || true" vcmd="/srv/zulip/tools/lint --no-gitlint --force $changed_files || true"
echo "Running lint using vagrant..." echo "Running lint using vagrant..."
vagrant ssh -c "$vcmd" vagrant ssh -c "$vcmd"
else else
./tools/lint --pep8 --no-gitlint --force $changed_files || true ./tools/lint --no-gitlint --force $changed_files || true
fi fi
exit 0 exit 0

View File

@ -38,7 +38,7 @@ run ./tools/clean-repo
run ./tools/run-mypy run ./tools/run-mypy
# travis/backend # travis/backend
run ./tools/lint --pep8 $FORCEARG run ./tools/lint $FORCEARG
run ./manage.py makemessages --locale en run ./manage.py makemessages --locale en
run env PYTHONWARNINGS=ignore ./tools/check-capitalization --no-generate run env PYTHONWARNINGS=ignore ./tools/check-capitalization --no-generate
run env PYTHONWARNINGS=ignore ./tools/check-frontend-i18n --no-generate run env PYTHONWARNINGS=ignore ./tools/check-frontend-i18n --no-generate

View File

@ -5,7 +5,7 @@ source tools/travis/activate-venv
set -e set -e
set -x set -x
./tools/lint --pep8 # Include the slow and thus non-default pep8 linter check ./tools/lint
./manage.py makemessages --locale en ./manage.py makemessages --locale en
PYTHONWARNINGS=ignore ./tools/check-capitalization --no-generate PYTHONWARNINGS=ignore ./tools/check-capitalization --no-generate
PYTHONWARNINGS=ignore ./tools/check-frontend-i18n --no-generate PYTHONWARNINGS=ignore ./tools/check-frontend-i18n --no-generate