2016-05-25 15:53:13 +02:00
|
|
|
#!/usr/bin/env python
|
2016-03-10 17:15:34 +01:00
|
|
|
from __future__ import print_function
|
2016-03-10 18:22:27 +01:00
|
|
|
from __future__ import absolute_import
|
2016-08-18 20:05:04 +02:00
|
|
|
from contextlib import contextmanager
|
2016-08-18 18:48:08 +02:00
|
|
|
import logging
|
2013-02-19 04:40:57 +01:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import optparse
|
|
|
|
import subprocess
|
2015-12-05 22:47:50 +01:00
|
|
|
import traceback
|
2016-08-18 18:42:17 +02:00
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
|
|
|
|
|
|
|
import lister
|
|
|
|
from typing import cast, Any, Callable, Dict, Iterator, List, Optional, Tuple
|
2016-03-22 21:20:33 +01:00
|
|
|
|
2016-08-18 18:58:08 +02:00
|
|
|
# Exclude some directories and files from lint checking
|
2016-12-28 04:48:43 +01:00
|
|
|
EXCLUDED_FILES = [
|
|
|
|
# Third-party code that doesn't match our style
|
|
|
|
"api/integrations/perforce/git_p4.py",
|
|
|
|
"puppet/apt/.forge-release",
|
|
|
|
"puppet/apt/README.md",
|
|
|
|
"static/third",
|
|
|
|
# Transifex syncs translation.json files without trailing
|
|
|
|
# newlines; there's nothing other than trailing newlines we'd be
|
|
|
|
# checking for in these anyway.
|
|
|
|
"static/locale",
|
|
|
|
]
|
2016-08-18 18:58:08 +02:00
|
|
|
|
2016-08-18 20:05:04 +02:00
|
|
|
@contextmanager
|
|
|
|
def bright_red_output():
|
2016-11-24 19:12:55 +01:00
|
|
|
# type: () -> Iterator[None]
|
2016-08-18 20:05:04 +02:00
|
|
|
# Make the lint output bright red
|
|
|
|
sys.stdout.write('\x1B[1;31m')
|
|
|
|
sys.stdout.flush()
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
# Restore normal terminal colors
|
|
|
|
sys.stdout.write('\x1B[0m')
|
|
|
|
|
|
|
|
|
2016-08-18 18:46:04 +02:00
|
|
|
def check_pyflakes(options, by_lang):
|
|
|
|
# type: (Any, Dict[str, List[str]]) -> bool
|
2017-03-19 21:09:54 +01:00
|
|
|
if len(by_lang['py']) == 0:
|
2016-08-18 18:46:04 +02:00
|
|
|
return False
|
|
|
|
failed = False
|
|
|
|
pyflakes = subprocess.Popen(['pyflakes'] + by_lang['py'],
|
2016-12-11 14:30:45 +01:00
|
|
|
stdout = subprocess.PIPE,
|
|
|
|
stderr = subprocess.PIPE,
|
|
|
|
universal_newlines = True)
|
2016-08-18 18:46:04 +02:00
|
|
|
|
|
|
|
# pyflakes writes some output (like syntax errors) to stderr. :/
|
|
|
|
for pipe in (pyflakes.stdout, pyflakes.stderr):
|
|
|
|
for ln in pipe:
|
2016-12-28 04:39:44 +01:00
|
|
|
if options.full or not (
|
2016-08-18 18:46:04 +02:00
|
|
|
('imported but unused' in ln or
|
|
|
|
'redefinition of unused' in ln or
|
2016-12-28 04:39:44 +01:00
|
|
|
# Our ipython startup pythonrc file intentionally imports *
|
2016-08-18 18:46:04 +02:00
|
|
|
("scripts/lib/pythonrc.py" in ln and
|
|
|
|
" import *' used; unable to detect undefined names" in ln) or
|
2016-12-28 04:39:44 +01:00
|
|
|
# Special dev_settings.py import
|
|
|
|
"from .prod_settings_template import *" in ln or
|
2016-12-28 04:52:25 +01:00
|
|
|
("settings.py" in ln and
|
|
|
|
("settings import *' used; unable to detect undefined names" in ln or
|
|
|
|
"may be undefined, or defined from star imports" in ln)) or
|
2016-11-27 04:40:18 +01:00
|
|
|
("zerver/tornado/ioloop_logging.py" in ln and
|
2016-08-18 18:46:04 +02:00
|
|
|
"redefinition of function 'instrument_tornado_ioloop'" in ln) or
|
|
|
|
("zephyr_mirror_backend.py:" in ln and
|
2016-12-28 04:39:44 +01:00
|
|
|
"redefinition of unused 'simplejson' from line" in ln))):
|
2016-08-18 18:46:04 +02:00
|
|
|
sys.stdout.write(ln)
|
|
|
|
failed = True
|
|
|
|
return failed
|
|
|
|
|
2016-11-09 14:07:29 +01:00
|
|
|
|
|
|
|
def check_pep8(files):
|
|
|
|
# type: (List[str]) -> bool
|
|
|
|
failed = False
|
|
|
|
ignored_rules = [
|
2017-01-24 05:19:58 +01:00
|
|
|
# Each of these rules are ignored for the explained reason.
|
|
|
|
|
|
|
|
# "multiple spaces before operator"
|
|
|
|
# There are several typos here, but also several instances that are
|
|
|
|
# being used for alignment in dict keys/values using the `dict`
|
|
|
|
# constructor. We could fix the alignment cases by switching to the `{}`
|
|
|
|
# constructor, but it makes fixing this rule a little less
|
|
|
|
# straightforward.
|
|
|
|
'E221',
|
|
|
|
|
2017-01-24 06:43:33 +01:00
|
|
|
# 'missing whitespace around arithmetic operator'
|
|
|
|
# This should possibly be cleaned up, though changing some of
|
|
|
|
# these may make the code less readable.
|
|
|
|
'E226',
|
|
|
|
|
2017-01-24 05:19:58 +01:00
|
|
|
# "unexpected spaces around keyword / parameter equals"
|
|
|
|
# Many of these should be fixed, but many are also being used for
|
|
|
|
# alignment/making the code easier to read.
|
|
|
|
'E251',
|
|
|
|
|
2017-01-24 06:43:33 +01:00
|
|
|
# 'at least two spaces before inline comment'
|
|
|
|
# This we should probably clean up, but has 800+ instances in
|
|
|
|
# conflict (many of them type comments), so fixing this will
|
|
|
|
# be a lot of churn.
|
|
|
|
'E261',
|
|
|
|
|
2017-01-24 05:19:58 +01:00
|
|
|
# "block comment should start with '#'"
|
|
|
|
# These serve to show which lines should be changed in files customized
|
|
|
|
# by the user. We could probably resolve one of E265 or E266 by
|
|
|
|
# standardizing on a single style for lines that the user might want to
|
|
|
|
# change.
|
|
|
|
'E265',
|
|
|
|
|
|
|
|
# "too many leading '#' for block comment"
|
|
|
|
# Most of these are there for valid reasons.
|
|
|
|
'E266',
|
|
|
|
|
2017-01-24 06:43:33 +01:00
|
|
|
# "expected 2 blank lines after class or function definition"
|
|
|
|
# Zulip only uses 1 blank line after class/function
|
|
|
|
# definitions; the PEP-8 recommendation results in super sparse code.
|
|
|
|
'E302', 'E305',
|
|
|
|
|
2017-01-24 05:19:58 +01:00
|
|
|
# "module level import not at top of file"
|
|
|
|
# Most of these are there for valid reasons, though there might be a
|
2017-01-24 06:43:33 +01:00
|
|
|
# few that could be eliminated.
|
2017-01-24 05:19:58 +01:00
|
|
|
'E402',
|
|
|
|
|
2017-01-24 06:43:33 +01:00
|
|
|
# "line too long"
|
|
|
|
# Zulip is a bit less strict about line length, and has its
|
|
|
|
# own check for this (see max_length)
|
|
|
|
'E501',
|
|
|
|
|
2017-01-24 05:19:58 +01:00
|
|
|
# "do not assign a lambda expression, use a def"
|
|
|
|
# Fixing these would probably reduce readability in most cases.
|
|
|
|
'E731',
|
2016-11-09 14:07:29 +01:00
|
|
|
]
|
2017-02-07 22:19:43 +01:00
|
|
|
if len(files) == 0:
|
|
|
|
return False
|
2016-11-09 14:07:29 +01:00
|
|
|
pep8 = subprocess.Popen(
|
|
|
|
['pycodestyle'] + files + ['--ignore={rules}'.format(rules=','.join(ignored_rules))],
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
|
|
|
for pipe in (pep8.stdout, pep8.stderr):
|
|
|
|
for ln in pipe:
|
|
|
|
sys.stdout.write(ln)
|
|
|
|
failed = True
|
|
|
|
return failed
|
|
|
|
|
|
|
|
|
2016-08-18 18:48:08 +02:00
|
|
|
def run_parallel(lint_functions):
|
|
|
|
# type: (Dict[str, Callable[[], int]]) -> bool
|
|
|
|
pids = []
|
|
|
|
for name, func in lint_functions.items():
|
|
|
|
pid = os.fork()
|
|
|
|
if pid == 0:
|
|
|
|
logging.info("start " + name)
|
|
|
|
result = func()
|
|
|
|
logging.info("finish " + name)
|
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
|
|
|
os._exit(result)
|
|
|
|
pids.append(pid)
|
|
|
|
failed = False
|
|
|
|
|
|
|
|
for pid in pids:
|
|
|
|
(_, status) = os.waitpid(pid, 0)
|
|
|
|
if status != 0:
|
|
|
|
failed = True
|
|
|
|
return failed
|
|
|
|
|
2016-08-18 20:05:42 +02:00
|
|
|
def build_custom_checkers(by_lang):
|
|
|
|
# type: (Dict[str, List[str]]) -> Tuple[Callable[[], bool], Callable[[], bool]]
|
2016-08-18 18:42:17 +02:00
|
|
|
RuleList = List[Dict[str, Any]]
|
|
|
|
|
|
|
|
def custom_check_file(fn, rules, skip_rules=None, max_length=None):
|
|
|
|
# type: (str, RuleList, Optional[Any], Optional[int]) -> bool
|
|
|
|
failed = False
|
|
|
|
lineFlag = False
|
|
|
|
for i, line in enumerate(open(fn)):
|
|
|
|
line_newline_stripped = line.strip('\n')
|
|
|
|
line_fully_stripped = line_newline_stripped.strip()
|
|
|
|
skip = False
|
|
|
|
lineFlag = True
|
|
|
|
for rule in skip_rules or []:
|
|
|
|
if re.match(rule, line):
|
|
|
|
skip = True
|
|
|
|
if skip:
|
|
|
|
continue
|
|
|
|
for rule in rules:
|
|
|
|
exclude_list = rule.get('exclude', set())
|
2016-12-03 03:49:30 +01:00
|
|
|
if fn in exclude_list or os.path.dirname(fn) in exclude_list:
|
2016-08-18 18:42:17 +02:00
|
|
|
continue
|
|
|
|
exclude_list = rule.get('exclude_line', set())
|
|
|
|
if (fn, line_fully_stripped) in exclude_list:
|
|
|
|
continue
|
2017-01-30 02:52:52 +01:00
|
|
|
if rule.get("include_only"):
|
|
|
|
found = False
|
|
|
|
for item in rule.get("include_only", set()):
|
|
|
|
if item in fn:
|
|
|
|
found = True
|
|
|
|
if not found:
|
|
|
|
continue
|
2016-08-18 18:42:17 +02:00
|
|
|
try:
|
|
|
|
line_to_check = line_fully_stripped
|
|
|
|
if rule.get('strip') is not None:
|
|
|
|
if rule['strip'] == '\n':
|
|
|
|
line_to_check = line_newline_stripped
|
|
|
|
else:
|
|
|
|
raise Exception("Invalid strip rule")
|
|
|
|
if re.search(rule['pattern'], line_to_check):
|
|
|
|
sys.stdout.write(rule['description'] + ' at %s line %s:\n' % (fn, i+1))
|
|
|
|
print(line)
|
|
|
|
failed = True
|
|
|
|
except Exception:
|
|
|
|
print("Exception with %s at %s line %s" % (rule['pattern'], fn, i+1))
|
|
|
|
traceback.print_exc()
|
2017-01-09 07:45:48 +01:00
|
|
|
if isinstance(line, bytes):
|
|
|
|
line_length = len(line.decode("utf-8"))
|
|
|
|
else:
|
|
|
|
line_length = len(line)
|
|
|
|
if (max_length is not None and line_length > max_length and
|
2016-08-19 21:03:09 +02:00
|
|
|
'# type' not in line and 'test' not in fn and 'example' not in fn and
|
2017-01-13 01:42:46 +01:00
|
|
|
not re.match("\[[ A-Za-z0-9_:,&()-]*\]: http.*", line) and
|
2016-12-28 04:43:43 +01:00
|
|
|
"#ignorelongline" not in line and 'migrations' not in fn):
|
2016-08-18 18:42:17 +02:00
|
|
|
print("Line too long (%s) at %s line %s: %s" % (len(line), fn, i+1, line_newline_stripped))
|
2017-01-09 07:42:19 +01:00
|
|
|
failed = True
|
2016-08-18 18:42:17 +02:00
|
|
|
lastLine = line
|
|
|
|
if lineFlag and '\n' not in lastLine:
|
|
|
|
print("No newline at the end of file. Fix with `sed -i '$a\\' %s`" % (fn,))
|
2013-06-27 20:03:28 +02:00
|
|
|
failed = True
|
2016-08-18 18:42:17 +02:00
|
|
|
return failed
|
|
|
|
|
|
|
|
whitespace_rules = [
|
|
|
|
# This linter should be first since bash_rules depends on it.
|
|
|
|
{'pattern': '\s+$',
|
|
|
|
'strip': '\n',
|
|
|
|
'description': 'Fix trailing whitespace'},
|
|
|
|
{'pattern': '\t',
|
|
|
|
'strip': '\n',
|
|
|
|
'exclude': set(['zerver/lib/bugdown/codehilite.py',
|
|
|
|
'tools/travis/success-http-headers.txt']),
|
|
|
|
'description': 'Fix tab-based whitespace'},
|
2017-01-24 06:34:26 +01:00
|
|
|
] # type: RuleList
|
2016-08-18 18:42:17 +02:00
|
|
|
markdown_whitespace_rules = list([rule for rule in whitespace_rules if rule['pattern'] != '\s+$']) + [
|
2016-12-08 02:13:27 +01:00
|
|
|
# Two spaces trailing a line with other content is okay--it's a markdown line break.
|
|
|
|
# This rule finds one space trailing a non-space, three or more trailing spaces, and
|
|
|
|
# spaces on an empty line.
|
|
|
|
{'pattern': '((?<!\s)\s$)|(\s\s\s+$)|(^\s+$)',
|
|
|
|
'strip': '\n',
|
|
|
|
'description': 'Fix trailing whitespace'},
|
2016-12-08 02:15:28 +01:00
|
|
|
{'pattern': '^#+[A-Za-z0-9]',
|
|
|
|
'strip': '\n',
|
|
|
|
'description': 'Missing space after # in heading'},
|
2017-01-24 06:02:39 +01:00
|
|
|
] # type: RuleList
|
2016-08-18 18:42:17 +02:00
|
|
|
js_rules = cast(RuleList, [
|
|
|
|
{'pattern': '[^_]function\(',
|
|
|
|
'description': 'The keyword "function" should be followed by a space'},
|
|
|
|
{'pattern': '.*blueslip.warning\(.*',
|
|
|
|
'description': 'The module blueslip has no function warning, try using blueslip.warn'},
|
|
|
|
{'pattern': '[)]{$',
|
|
|
|
'description': 'Missing space between ) and {'},
|
|
|
|
{'pattern': '["\']json/',
|
|
|
|
'description': 'Relative URL for JSON route not supported by i18n'},
|
|
|
|
# This rule is constructed with + to avoid triggering on itself
|
|
|
|
{'pattern': " =" + '[^ =>~"]',
|
|
|
|
'description': 'Missing whitespace after "="'},
|
|
|
|
{'pattern': '^[ ]*//[A-Za-z0-9]',
|
|
|
|
'description': 'Missing space after // in comment'},
|
|
|
|
{'pattern': 'if[(]',
|
|
|
|
'description': 'Missing space between if and ('},
|
|
|
|
{'pattern': 'else{$',
|
|
|
|
'description': 'Missing space between else and {'},
|
|
|
|
{'pattern': '^else {$',
|
|
|
|
'description': 'Write JS else statements on same line as }'},
|
|
|
|
{'pattern': '^else if',
|
|
|
|
'description': 'Write JS else statements on same line as }'},
|
2016-12-03 03:49:30 +01:00
|
|
|
{'pattern': 'console[.][a-z]',
|
|
|
|
'exclude': set(['static/js/blueslip.js',
|
|
|
|
'frontend_tests/zjsunit',
|
|
|
|
'frontend_tests/casper_lib/common.js',
|
|
|
|
'frontend_tests/node_tests',
|
|
|
|
'static/js/debug.js']),
|
|
|
|
'description': 'console.log and similar should not be used in webapp'},
|
2017-03-17 22:13:11 +01:00
|
|
|
{'pattern': 'i18n[.]t',
|
|
|
|
'include_only': set(['static/js/portico']),
|
|
|
|
'description': 'i18n.t is not available in portico pages yet'},
|
2017-03-01 05:36:51 +01:00
|
|
|
{'pattern': '[.]text\(["\'][a-zA-Z]',
|
|
|
|
'description': 'Strings passed to $().text should be wrapped in i18n.t() for internationalization'},
|
2016-08-18 18:42:17 +02:00
|
|
|
{'pattern': 'compose_error\(["\']',
|
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
'description': 'Argument to compose_error should be a literal string enclosed '
|
|
|
|
'by i18n.t()'},
|
2017-03-22 14:57:23 +01:00
|
|
|
{'pattern': 'ui.report_success\(',
|
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
'description': 'Deprecated function, use ui_report.success.'},
|
|
|
|
{'pattern': 'report.success\(["\']',
|
2016-08-18 18:42:17 +02:00
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
'description': 'Argument to report_success should be a literal string enclosed '
|
|
|
|
'by i18n.t()'},
|
2017-03-22 14:57:23 +01:00
|
|
|
{'pattern': 'ui.report_error\(',
|
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
'description': 'Deprecated function, use ui_report.error.'},
|
|
|
|
{'pattern': 'report.error\(["\']',
|
2016-08-18 18:42:17 +02:00
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
'description': 'Argument to report_error should be a literal string enclosed '
|
|
|
|
'by i18n.t()'},
|
2017-01-24 06:34:26 +01:00
|
|
|
]) + whitespace_rules
|
2016-08-18 18:42:17 +02:00
|
|
|
python_rules = cast(RuleList, [
|
|
|
|
{'pattern': '^(?!#)@login_required',
|
|
|
|
'description': '@login_required is unsupported; use @zulip_login_required'},
|
|
|
|
{'pattern': '".*"%\([a-z_].*\)?$',
|
|
|
|
'description': 'Missing space around "%"'},
|
|
|
|
{'pattern': "'.*'%\([a-z_].*\)?$",
|
2016-07-29 21:52:45 +02:00
|
|
|
'exclude': set(['tools/lint-all',
|
|
|
|
'analytics/lib/counts.py',
|
2016-11-04 00:48:11 +01:00
|
|
|
'analytics/tests/test_counts.py',
|
2016-07-29 21:52:45 +02:00
|
|
|
]),
|
2016-08-18 18:42:17 +02:00
|
|
|
'exclude_line': set([
|
|
|
|
('zerver/views/users.py',
|
2017-03-13 17:37:01 +01:00
|
|
|
"return json_error(_(\"Email '%(email)s' not allowed for realm '%(realm)s'\") %"),
|
2016-12-28 04:52:25 +01:00
|
|
|
('zproject/settings.py',
|
|
|
|
"'format': '%(asctime)s %(levelname)-8s %(message)s'"),
|
2016-08-18 18:42:17 +02:00
|
|
|
]),
|
|
|
|
'description': 'Missing space around "%"'},
|
|
|
|
# This rule is constructed with + to avoid triggering on itself
|
|
|
|
{'pattern': " =" + '[^ =>~"]',
|
|
|
|
'description': 'Missing whitespace after "="'},
|
|
|
|
{'pattern': '":\w[^"]*$',
|
|
|
|
'description': 'Missing whitespace after ":"'},
|
|
|
|
{'pattern': "':\w[^']*$",
|
|
|
|
'description': 'Missing whitespace after ":"'},
|
|
|
|
{'pattern': "^\s+[#]\w",
|
|
|
|
'strip': '\n',
|
|
|
|
'description': 'Missing whitespace after "#"'},
|
2017-02-09 01:32:42 +01:00
|
|
|
{'pattern': "assertEquals[(]",
|
|
|
|
'description': 'Use assertEqual, not assertEquals (which is deprecated).'},
|
2016-08-18 18:42:17 +02:00
|
|
|
{'pattern': "== None",
|
|
|
|
'exclude': 'tools/lint-all',
|
|
|
|
'description': 'Use `is None` to check whether something is None'},
|
|
|
|
{'pattern': "type:[(]",
|
|
|
|
'description': 'Missing whitespace after ":" in type annotation'},
|
|
|
|
{'pattern': "# type [(]",
|
|
|
|
'description': 'Missing : after type in type annotation'},
|
|
|
|
{'pattern': "#type",
|
|
|
|
'exclude': 'tools/lint-all',
|
|
|
|
'description': 'Missing whitespace after "#" in type annotation'},
|
|
|
|
{'pattern': 'if[(]',
|
|
|
|
'description': 'Missing space between if and ('},
|
|
|
|
{'pattern': ", [)]",
|
|
|
|
'description': 'Unnecessary whitespace between "," and ")"'},
|
|
|
|
{'pattern': "% [(]",
|
|
|
|
'description': 'Unnecessary whitespace between "%" and "("'},
|
|
|
|
# This next check could have false positives, but it seems pretty
|
|
|
|
# rare; if we find any, they can be added to the exclude list for
|
|
|
|
# this rule.
|
2017-02-19 01:29:36 +01:00
|
|
|
{'pattern': ' % [a-zA-Z0-9_.]*\)?$',
|
2016-08-31 00:43:08 +02:00
|
|
|
'exclude_line': set([
|
|
|
|
('tools/tests/test_template_parser.py', '{% foo'),
|
|
|
|
]),
|
2016-08-18 18:42:17 +02:00
|
|
|
'description': 'Used % comprehension without a tuple'},
|
2017-01-09 20:45:11 +01:00
|
|
|
{'pattern': '.*%s.* % \([a-zA-Z0-9_.]*\)$',
|
|
|
|
'description': 'Used % comprehension without a tuple'},
|
2017-03-09 09:03:21 +01:00
|
|
|
{'pattern': 'django.utils.translation',
|
|
|
|
'include_only': set(['test']),
|
|
|
|
'description': 'Test strings should not be tagged for translationx'},
|
2016-10-21 07:34:04 +02:00
|
|
|
{'pattern': 'json_success\({}\)',
|
|
|
|
'description': 'Use json_success() to return nothing'},
|
2016-08-18 18:42:17 +02:00
|
|
|
# To avoid json_error(_variable) and json_error(_(variable))
|
|
|
|
{'pattern': '\Wjson_error\(_\(?\w+\)',
|
2017-03-09 09:03:21 +01:00
|
|
|
'exclude': set(['tools/lint-all', 'zerver/tests']),
|
2016-08-18 18:42:17 +02:00
|
|
|
'description': 'Argument to json_error should be a literal string enclosed by _()'},
|
2017-03-01 02:34:01 +01:00
|
|
|
{'pattern': '\Wjson_error\([\'"].+[),]$',
|
2017-03-09 09:03:21 +01:00
|
|
|
'exclude': set(['tools/lint-all', 'zerver/tests']),
|
2016-08-18 18:42:17 +02:00
|
|
|
'exclude_line': set([
|
2017-03-01 02:34:01 +01:00
|
|
|
# We don't want this string tagged for translation.
|
2017-01-30 07:21:13 +01:00
|
|
|
('zerver/views/compatibility.py', 'return json_error("Client is too old")'),
|
2016-08-18 18:42:17 +02:00
|
|
|
]),
|
|
|
|
'description': 'Argument to json_error should a literal string enclosed by _()'},
|
|
|
|
# To avoid JsonableError(_variable) and JsonableError(_(variable))
|
|
|
|
{'pattern': '\WJsonableError\(_\(?\w.+\)',
|
2017-03-09 09:03:21 +01:00
|
|
|
'exclude': set(['tools/lint-all', 'zerver/tests']),
|
2016-08-18 18:42:17 +02:00
|
|
|
'description': 'Argument to JsonableError should be a literal string enclosed by _()'},
|
2017-03-01 02:34:01 +01:00
|
|
|
{'pattern': '\WJsonableError\(["\'].+\)',
|
2017-03-09 09:03:21 +01:00
|
|
|
'exclude': set(['tools/lint-all', 'zerver/tests']),
|
2016-08-18 18:42:17 +02:00
|
|
|
'description': 'Argument to JsonableError should be a literal string enclosed by _()'},
|
|
|
|
{'pattern': '([a-zA-Z0-9_]+)=REQ\([\'"]\\1[\'"]',
|
|
|
|
'description': 'REQ\'s first argument already defaults to parameter name'},
|
|
|
|
{'pattern': 'self\.client\.(get|post|patch|put|delete)',
|
|
|
|
'exclude': set(['zilencer/tests.py']),
|
|
|
|
'description': \
|
2016-12-11 14:30:45 +01:00
|
|
|
'''Do not call self.client directly for put/patch/post/get.
|
2016-08-18 18:42:17 +02:00
|
|
|
See WRAPPER_COMMENT in test_helpers.py for details.
|
|
|
|
'''},
|
2017-01-20 00:59:06 +01:00
|
|
|
# Directly fetching Message objects in e.g. views code is often a security bug.
|
|
|
|
{'pattern': '[^r][M]essage.objects.get',
|
|
|
|
'exclude': set(["zerver/tests", "zerver/worker/queue_processors.py"]),
|
|
|
|
'description': 'Please use access_message() to fetch Message objects',
|
2017-01-20 01:42:42 +01:00
|
|
|
},
|
2017-01-30 02:52:52 +01:00
|
|
|
{'pattern': '[S]tream.objects.get',
|
|
|
|
'include_only': set(["zerver/views/"]),
|
|
|
|
'description': 'Please use access_stream_by_*() to fetch Stream objects',
|
|
|
|
},
|
2017-01-30 03:29:37 +01:00
|
|
|
{'pattern': 'get_stream[(]',
|
2017-01-30 04:34:53 +01:00
|
|
|
'include_only': set(["zerver/views/", "zerver/lib/actions.py"]),
|
|
|
|
# messages.py needs to support accessing invite-only streams
|
|
|
|
# that you are no longer subscribed to, so need get_stream.
|
2017-01-30 03:29:37 +01:00
|
|
|
'exclude': set(['zerver/views/messages.py']),
|
2017-01-30 04:08:03 +01:00
|
|
|
'exclude_line': set([
|
2017-01-30 04:34:53 +01:00
|
|
|
# This is a check for whether a stream rename is invalid because it already exists
|
2017-03-23 23:50:33 +01:00
|
|
|
('zerver/lib/actions.py', 'get_stream(new_name, stream.realm)'),
|
2017-01-30 04:34:53 +01:00
|
|
|
# This one in check_message is kinda terrible, since it's
|
|
|
|
# how most instances are written, but better to exclude something than nothing
|
|
|
|
('zerver/lib/actions.py', 'stream = get_stream(stream_name, realm)'),
|
2017-03-24 05:49:23 +01:00
|
|
|
('zerver/lib/actions.py', 'get_stream(signups_stream, admin_realm)'),
|
2017-01-30 04:08:03 +01:00
|
|
|
]),
|
2017-01-30 03:29:37 +01:00
|
|
|
'description': 'Please use access_stream_by_*() to fetch Stream objects',
|
|
|
|
},
|
2017-01-30 02:52:52 +01:00
|
|
|
{'pattern': '[S]tream.objects.filter',
|
|
|
|
'include_only': set(["zerver/views/"]),
|
|
|
|
'description': 'Please use access_stream_by_*() to fetch Stream objects',
|
|
|
|
},
|
2017-03-15 03:48:55 +01:00
|
|
|
{'pattern': '^from (zerver|analytics|confirmation)',
|
2017-03-05 02:29:08 +01:00
|
|
|
'include_only': set(["/migrations/"]),
|
2017-03-15 03:48:55 +01:00
|
|
|
'exclude': set(['zerver/migrations/0032_verify_all_medium_avatar_images.py',
|
|
|
|
'zerver/migrations/0041_create_attachments_for_old_messages.py',
|
|
|
|
'zerver/migrations/0060_move_avatars_to_be_uid_based.py']),
|
|
|
|
'description': "Don't import models or other code in migrations; see docs/schema-migrations.md",
|
2017-03-05 02:29:08 +01:00
|
|
|
},
|
2017-03-09 06:02:30 +01:00
|
|
|
{'pattern': 'datetime[.](now|utcnow)',
|
|
|
|
'include_only': set(["zerver/", "analytics/"]),
|
|
|
|
'description': "Don't use datetime in backend code.\n"
|
|
|
|
"See https://zulip.readthedocs.io/en/latest/code-style.html#naive-datetime-objects",
|
|
|
|
},
|
2017-03-20 09:41:19 +01:00
|
|
|
{'pattern': 'render_to_response\(',
|
|
|
|
'description': "Use render() instead of render_to_response().",
|
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
},
|
2016-12-18 23:11:24 +01:00
|
|
|
# This rule might give false positives in virtualenv setup files which should be excluded,
|
|
|
|
# and comments which should be rewritten to avoid use of "python2", "python3", etc.
|
|
|
|
{'pattern': 'python[23]',
|
2017-01-14 11:19:26 +01:00
|
|
|
'exclude': set(['tools/lib/provision.py',
|
2016-12-18 23:11:24 +01:00
|
|
|
'tools/setup/setup_venvs.py',
|
|
|
|
'scripts/lib/setup_venv.py',
|
|
|
|
'tools/lint-all']),
|
|
|
|
'description': 'Explicit python invocations should not include a version'}
|
2017-01-24 06:34:26 +01:00
|
|
|
]) + whitespace_rules
|
2016-08-18 18:42:17 +02:00
|
|
|
bash_rules = [
|
|
|
|
{'pattern': '#!.*sh [-xe]',
|
2016-08-19 20:33:53 +02:00
|
|
|
'description': 'Fix shebang line with proper call to /usr/bin/env for Bash path, change -x|-e switches'
|
|
|
|
' to set -x|set -e'},
|
2017-01-24 06:34:26 +01:00
|
|
|
] + whitespace_rules[0:1] # type: RuleList
|
2016-09-28 03:38:32 +02:00
|
|
|
css_rules = cast(RuleList, [
|
2016-08-18 18:42:17 +02:00
|
|
|
{'pattern': '^[^:]*:\S[^:]*;$',
|
|
|
|
'description': "Missing whitespace after : in CSS"},
|
|
|
|
{'pattern': '[a-z]{',
|
|
|
|
'description': "Missing whitespace before '{' in CSS."},
|
2016-12-16 07:02:10 +01:00
|
|
|
{'pattern': 'https://',
|
|
|
|
'description': "Zulip CSS should have no dependencies on external resources"},
|
2016-09-28 03:06:44 +02:00
|
|
|
{'pattern': '^[ ][ ][a-zA-Z0-9]',
|
|
|
|
'description': "Incorrect 2-space indentation in CSS",
|
2017-03-19 00:22:09 +01:00
|
|
|
'exclude': set(['static/third/thirdparty-fonts.css']),
|
2016-11-30 21:55:59 +01:00
|
|
|
'strip': '\n'},
|
2016-08-18 18:42:17 +02:00
|
|
|
{'pattern': '{\w',
|
|
|
|
'description': "Missing whitespace after '{' in CSS (should be newline)."},
|
2017-04-21 00:04:39 +02:00
|
|
|
{'pattern': ' thin[; ]',
|
|
|
|
'description': "thin CSS attribute is under-specified, please use 1px."},
|
|
|
|
{'pattern': ' medium[; ]',
|
|
|
|
'description': "medium CSS attribute is under-specified, please use pixels."},
|
|
|
|
{'pattern': ' thick[; ]',
|
|
|
|
'description': "thick CSS attribute is under-specified, please use pixels."},
|
2017-01-24 06:34:26 +01:00
|
|
|
]) + whitespace_rules # type: RuleList
|
2016-10-16 17:40:16 +02:00
|
|
|
prose_style_rules = [
|
|
|
|
{'pattern': '[^\/\#\-\"]([jJ]avascript)', # exclude usage in hrefs/divs
|
|
|
|
'description': "javascript should be spelled JavaScript"},
|
2016-12-02 08:15:05 +01:00
|
|
|
{'pattern': '[^\/\-\.\"\'\_\=\>]([gG]ithub)[^\.\-\_\"\<]', # exclude usage in hrefs/divs
|
2016-10-21 23:14:39 +02:00
|
|
|
'description': "github should be spelled GitHub"},
|
2016-12-28 02:25:01 +01:00
|
|
|
{'pattern': '[oO]rganisation', # exclude usage in hrefs/divs
|
|
|
|
'description': "Organization is spelled with a z"},
|
2017-01-06 00:14:54 +01:00
|
|
|
{'pattern': '!!! warning',
|
|
|
|
'description': "!!! warning is invalid; it's spelled '!!! warn'"},
|
2016-10-16 17:40:16 +02:00
|
|
|
] # type: RuleList
|
|
|
|
html_rules = whitespace_rules + prose_style_rules + [
|
2016-08-18 18:42:17 +02:00
|
|
|
{'pattern': 'placeholder="[^{]',
|
2016-10-16 21:59:25 +02:00
|
|
|
'description': "`placeholder` value should be translatable.",
|
2017-03-09 09:24:21 +01:00
|
|
|
'exclude_line': [('templates/zerver/register.html', 'placeholder="acme"'),
|
|
|
|
('templates/zerver/register.html', 'placeholder="Acme"'),
|
|
|
|
('static/templates/settings/realm-domains-modal.handlebars',
|
2017-03-31 22:40:48 +02:00
|
|
|
'<td><input type="text" class="new-realm-domain" placeholder="acme.com"></input></td>')],
|
2016-02-13 19:17:15 +01:00
|
|
|
'exclude': set(["static/templates/settings/emoji-settings-admin.handlebars",
|
2017-01-29 00:08:08 +01:00
|
|
|
"static/templates/settings/realm-filter-settings-admin.handlebars",
|
|
|
|
"static/templates/settings/bot-settings.handlebars"])},
|
2016-08-18 18:42:17 +02:00
|
|
|
{'pattern': "placeholder='[^{]",
|
|
|
|
'description': "`placeholder` value should be translatable."},
|
2017-03-05 05:42:12 +01:00
|
|
|
{'pattern': 'script src="http',
|
|
|
|
'description': "Don't directly load dependencies from CDNs. See docs/front-end-build-process.md"},
|
2016-12-15 08:33:10 +01:00
|
|
|
{'pattern': "title='[^{]",
|
|
|
|
'description': "`title` value should be translatable."},
|
2017-01-28 00:25:01 +01:00
|
|
|
{'pattern': 'title="[^{\:]',
|
2016-12-15 08:33:10 +01:00
|
|
|
'exclude_line': set([
|
|
|
|
('templates/zerver/markdown_help.html',
|
2016-12-28 05:07:10 +01:00
|
|
|
'<td><img alt=":heart:" class="emoji" src="/static/generated/emoji/images/emoji/heart.png" title=":heart:" /></td>')
|
2016-12-15 08:33:10 +01:00
|
|
|
]),
|
|
|
|
'description': "`title` value should be translatable."},
|
2017-01-24 06:34:26 +01:00
|
|
|
] # type: RuleList
|
2016-12-30 21:43:19 +01:00
|
|
|
handlebars_rules = html_rules + [
|
|
|
|
{'pattern': "[<]script",
|
|
|
|
'description': "Do not use inline <script> tags here; put JavaScript in static/js instead."},
|
2017-03-09 12:46:23 +01:00
|
|
|
{'pattern': "{{t '.*' }}[\.\?!]",
|
|
|
|
'description': "Period should be part of the translatable string."},
|
|
|
|
{'pattern': '{{t ".*" }}[\.\?!]',
|
|
|
|
'description': "Period should be part of the translatable string."},
|
|
|
|
{'pattern': "{{/tr}}[\.\?!]",
|
|
|
|
'description': "Period should be part of the translatable string."},
|
|
|
|
]
|
|
|
|
jinja2_rules = html_rules + [
|
|
|
|
{'pattern': "{% endtrans %}[\.\?!]",
|
|
|
|
'description': "Period should be part of the translatable string."},
|
|
|
|
{'pattern': "{{ _(.+) }}[\.\?!]",
|
|
|
|
'description': "Period should be part of the translatable string."},
|
2016-12-30 21:43:19 +01:00
|
|
|
]
|
2016-10-16 18:55:52 +02:00
|
|
|
json_rules = [] # type: RuleList # fix newlines at ends of files
|
|
|
|
# It is okay that json_rules is empty, because the empty list
|
|
|
|
# ensures we'll still check JSON files for whitespace.
|
2017-03-19 21:44:04 +01:00
|
|
|
markdown_rules = markdown_whitespace_rules + prose_style_rules + [
|
|
|
|
{'pattern': '\[(?P<url>[^\]]+)\]\((?P=url)\)',
|
|
|
|
'description': 'Linkified markdown URLs should use cleaner <http://example.com> syntax.'}
|
|
|
|
]
|
2017-01-06 20:18:45 +01:00
|
|
|
help_markdown_rules = markdown_rules + [
|
|
|
|
{'pattern': '[a-z][.][A-Z]',
|
|
|
|
'description': "Likely missing space after end of sentence"},
|
2017-01-09 05:46:03 +01:00
|
|
|
{'pattern': '[rR]ealm',
|
|
|
|
'description': "Realms are referred to as Organizations in user-facing docs."},
|
2017-01-06 20:18:45 +01:00
|
|
|
]
|
2016-08-18 18:42:17 +02:00
|
|
|
txt_rules = whitespace_rules
|
2016-06-17 19:26:48 +02:00
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
def check_custom_checks_py():
|
|
|
|
# type: () -> bool
|
|
|
|
failed = False
|
2013-06-27 20:03:28 +02:00
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
for fn in by_lang['py']:
|
2016-08-19 21:03:09 +02:00
|
|
|
if custom_check_file(fn, python_rules, max_length=140):
|
2016-08-18 18:42:17 +02:00
|
|
|
failed = True
|
|
|
|
return failed
|
2013-07-05 18:53:43 +02:00
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
def check_custom_checks_nonpy():
|
|
|
|
# type: () -> bool
|
|
|
|
failed = False
|
2016-01-17 17:24:31 +01:00
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
for fn in by_lang['js']:
|
|
|
|
if custom_check_file(fn, js_rules):
|
|
|
|
failed = True
|
2016-04-08 20:38:25 +02:00
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
for fn in by_lang['sh']:
|
|
|
|
if custom_check_file(fn, bash_rules):
|
|
|
|
failed = True
|
2016-04-08 20:45:47 +02:00
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
for fn in by_lang['css']:
|
|
|
|
if custom_check_file(fn, css_rules):
|
|
|
|
failed = True
|
2016-04-08 20:44:39 +02:00
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
for fn in by_lang['handlebars']:
|
|
|
|
if custom_check_file(fn, handlebars_rules):
|
|
|
|
failed = True
|
2016-04-14 19:48:30 +02:00
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
for fn in by_lang['html']:
|
2017-03-09 12:46:23 +01:00
|
|
|
if custom_check_file(fn, jinja2_rules):
|
2016-08-18 18:42:17 +02:00
|
|
|
failed = True
|
2016-04-14 23:29:58 +02:00
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
for fn in by_lang['json']:
|
|
|
|
if custom_check_file(fn, json_rules):
|
|
|
|
failed = True
|
2016-04-14 23:34:04 +02:00
|
|
|
|
2017-01-06 00:06:34 +01:00
|
|
|
markdown_docs_length_exclude = {
|
2017-02-08 22:05:24 +01:00
|
|
|
"contrib_bots/bots/converter/readme.md",
|
2017-01-06 00:06:34 +01:00
|
|
|
"docs/bots-guide.md",
|
|
|
|
"docs/dev-env-first-time-contributors.md",
|
2017-02-06 22:07:45 +01:00
|
|
|
"docs/webhook-walkthrough.md",
|
2017-01-06 00:06:34 +01:00
|
|
|
"docs/life-of-a-request.md",
|
|
|
|
"docs/logging.md",
|
|
|
|
"docs/migration-renumbering.md",
|
|
|
|
"docs/readme-symlink.md",
|
|
|
|
"README.md",
|
2017-04-04 10:20:31 +02:00
|
|
|
"zerver/webhooks/trello/doc.md",
|
2017-01-06 00:06:34 +01:00
|
|
|
}
|
2016-08-18 18:42:17 +02:00
|
|
|
for fn in by_lang['md']:
|
2017-01-05 23:08:16 +01:00
|
|
|
max_length = None
|
2017-01-06 00:06:34 +01:00
|
|
|
if fn not in markdown_docs_length_exclude:
|
2017-01-05 23:08:16 +01:00
|
|
|
max_length = 120
|
2017-01-06 20:18:45 +01:00
|
|
|
rules = markdown_rules
|
|
|
|
if fn.startswith("templates/zerver/help"):
|
|
|
|
rules = help_markdown_rules
|
|
|
|
if custom_check_file(fn, rules, max_length=max_length):
|
2016-08-18 18:42:17 +02:00
|
|
|
failed = True
|
2013-11-27 19:00:08 +01:00
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
for fn in by_lang['txt'] + by_lang['text']:
|
|
|
|
if custom_check_file(fn, txt_rules):
|
|
|
|
failed = True
|
2013-11-27 19:00:08 +01:00
|
|
|
|
2017-01-24 02:10:38 +01:00
|
|
|
for fn in by_lang['yaml']:
|
|
|
|
if custom_check_file(fn, txt_rules):
|
|
|
|
failed = True
|
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
return failed
|
|
|
|
|
2016-08-18 20:05:42 +02:00
|
|
|
return (check_custom_checks_py, check_custom_checks_nonpy)
|
|
|
|
|
|
|
|
def run():
|
|
|
|
# type: () -> None
|
|
|
|
parser = optparse.OptionParser()
|
2016-11-23 18:28:21 +01:00
|
|
|
parser.add_option('--force', default=False,
|
2016-12-11 14:30:45 +01:00
|
|
|
action="store_true",
|
|
|
|
help='Run tests despite possible problems.')
|
2016-08-18 20:05:42 +02:00
|
|
|
parser.add_option('--full',
|
2016-12-11 14:30:45 +01:00
|
|
|
action='store_true',
|
|
|
|
help='Check some things we typically ignore')
|
2016-11-09 14:07:29 +01:00
|
|
|
parser.add_option('--pep8',
|
2016-12-11 14:30:45 +01:00
|
|
|
action='store_true',
|
|
|
|
help='Run the pep8 checker')
|
2016-08-18 20:05:42 +02:00
|
|
|
parser.add_option('--modified', '-m',
|
2016-12-11 14:30:45 +01:00
|
|
|
action='store_true',
|
|
|
|
help='Only check modified files')
|
2016-08-18 20:05:42 +02:00
|
|
|
parser.add_option('--verbose', '-v',
|
2016-12-11 14:30:45 +01:00
|
|
|
action='store_true',
|
|
|
|
help='Print verbose timing output')
|
2016-08-18 20:05:42 +02:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
2016-11-23 18:28:21 +01:00
|
|
|
tools_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
root_dir = os.path.dirname(tools_dir)
|
|
|
|
sys.path.insert(0, root_dir)
|
|
|
|
|
|
|
|
from tools.lib.test_script import (
|
|
|
|
get_provisioning_status,
|
|
|
|
)
|
|
|
|
|
|
|
|
os.chdir(root_dir)
|
|
|
|
|
|
|
|
if not options.force:
|
|
|
|
ok, msg = get_provisioning_status()
|
|
|
|
if not ok:
|
|
|
|
print(msg)
|
|
|
|
print('If you really know what you are doing, use --force to run anyway.')
|
|
|
|
sys.exit(1)
|
2016-08-18 20:05:42 +02:00
|
|
|
|
2016-12-11 14:30:45 +01:00
|
|
|
by_lang = cast(Dict[str, List[str]],
|
|
|
|
lister.list_files(args, modified_only=options.modified,
|
|
|
|
ftypes=['py', 'sh', 'js', 'pp', 'css', 'handlebars',
|
2017-01-24 02:10:38 +01:00
|
|
|
'html', 'json', 'md', 'txt', 'text', 'yaml'],
|
2016-12-11 14:30:45 +01:00
|
|
|
use_shebang=True, group_by_ftype=True, exclude=EXCLUDED_FILES))
|
2016-08-18 20:05:42 +02:00
|
|
|
|
|
|
|
# Invoke the appropriate lint checker for each language,
|
|
|
|
# and also check files for extra whitespace.
|
|
|
|
|
|
|
|
logging.basicConfig(format="%(asctime)s %(message)s")
|
|
|
|
logger = logging.getLogger()
|
|
|
|
if options.verbose:
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
else:
|
|
|
|
logger.setLevel(logging.WARNING)
|
|
|
|
|
|
|
|
check_custom_checks_py, check_custom_checks_nonpy = build_custom_checkers(by_lang)
|
|
|
|
|
2016-08-18 18:42:17 +02:00
|
|
|
lint_functions = {} # type: Dict[str, Callable[[], int]]
|
|
|
|
|
|
|
|
def lint(func):
|
|
|
|
# type: (Callable[[], int]) -> Callable[[], int]
|
|
|
|
lint_functions[func.__name__] = func
|
|
|
|
return func
|
|
|
|
|
2017-03-19 21:25:20 +01:00
|
|
|
def external_linter(name, command, target_langs=[]):
|
|
|
|
# type: (str, List[str], List[str]) -> None
|
|
|
|
def run_linter():
|
2016-11-04 23:15:18 +01:00
|
|
|
# type: () -> int
|
2017-03-19 21:25:20 +01:00
|
|
|
if len(target_langs) == 0:
|
|
|
|
return subprocess.call(command)
|
|
|
|
targets = [target for lang in target_langs for target in by_lang[lang]]
|
|
|
|
if len(targets) == 0:
|
2016-11-19 01:18:08 +01:00
|
|
|
return 0
|
2017-03-19 21:25:20 +01:00
|
|
|
return subprocess.call(command + targets)
|
|
|
|
lint_functions[name] = run_linter
|
2016-11-04 23:15:18 +01:00
|
|
|
|
2017-03-19 21:25:20 +01:00
|
|
|
with bright_red_output():
|
|
|
|
external_linter('add_class', ['tools/find-add-class'])
|
|
|
|
external_linter('css', ['tools/check-css'], ['css'])
|
|
|
|
external_linter('eslint', ['node', 'node_modules/.bin/eslint', '--quiet'], ['js'])
|
|
|
|
external_linter('puppet', ['puppet', 'parser', 'validate'], ['pp'])
|
|
|
|
external_linter('templates', ['tools/check-templates'], ['handlebars', 'html'])
|
|
|
|
external_linter('urls', ['tools/check-urls'])
|
2016-08-18 18:42:17 +02:00
|
|
|
|
|
|
|
@lint
|
|
|
|
def custom_py():
|
|
|
|
# type: () -> int
|
|
|
|
failed = check_custom_checks_py()
|
|
|
|
return 1 if failed else 0
|
|
|
|
|
|
|
|
@lint
|
|
|
|
def custom_nonpy():
|
|
|
|
# type: () -> int
|
|
|
|
failed = check_custom_checks_nonpy()
|
|
|
|
return 1 if failed else 0
|
|
|
|
|
|
|
|
@lint
|
|
|
|
def pyflakes():
|
|
|
|
# type: () -> int
|
2016-08-18 18:46:04 +02:00
|
|
|
failed = check_pyflakes(options, by_lang)
|
2016-08-18 18:42:17 +02:00
|
|
|
return 1 if failed else 0
|
|
|
|
|
2016-11-09 14:07:29 +01:00
|
|
|
if options.pep8:
|
|
|
|
@lint
|
|
|
|
def pep8():
|
|
|
|
# type: () -> int
|
|
|
|
failed = check_pep8(by_lang['py'])
|
|
|
|
return 1 if failed else 0
|
|
|
|
|
2016-08-18 18:48:08 +02:00
|
|
|
failed = run_parallel(lint_functions)
|
2016-08-18 18:42:17 +02:00
|
|
|
|
2016-08-18 20:05:04 +02:00
|
|
|
sys.exit(1 if failed else 0)
|
2016-08-18 18:42:17 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run()
|