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',
action='store_true',
help='Check some things we typically ignore')
parser.add_argument('--pep8',
action='store_true',
help='Run the pep8 checker')
parser.add_argument('--no-gitlint',
action='store_true',
help='Disable gitlint')
@ -62,6 +59,13 @@ def run():
parser.add_argument('targets',
nargs='*',
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()
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.')
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]],
lister.list_files(args.targets, modified_only=args.modified,
ftypes=['py', 'sh', 'js', 'pp', 'css', 'handlebars',
'html', 'json', 'md', 'txt', 'text', 'yaml'],
ftypes=file_types,
use_shebang=True, group_by_ftype=True, exclude=EXCLUDED_FILES))
# Invoke the appropriate lint checker for each language,
@ -178,12 +189,11 @@ def run():
failed = check_pyflakes(args, by_lang)
return 1 if failed else 0
if args.pep8:
@lint
def pep8():
# type: () -> int
failed = check_pep8(by_lang['py'])
return 1 if failed else 0
@lint
def pep8():
# type: () -> int
failed = check_pep8(by_lang['py'])
return 1 if failed else 0
failed = run_parallel(lint_functions)

View File

@ -16,10 +16,10 @@ if [ -z "$changed_files" ]; then
fi
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..."
vagrant ssh -c "$vcmd"
else
./tools/lint --pep8 --no-gitlint --force $changed_files || true
./tools/lint --no-gitlint --force $changed_files || true
fi
exit 0

View File

@ -38,7 +38,7 @@ run ./tools/clean-repo
run ./tools/run-mypy
# travis/backend
run ./tools/lint --pep8 $FORCEARG
run ./tools/lint $FORCEARG
run ./manage.py makemessages --locale en
run env PYTHONWARNINGS=ignore ./tools/check-capitalization --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 -x
./tools/lint --pep8 # Include the slow and thus non-default pep8 linter check
./tools/lint
./manage.py makemessages --locale en
PYTHONWARNINGS=ignore ./tools/check-capitalization --no-generate
PYTHONWARNINGS=ignore ./tools/check-frontend-i18n --no-generate