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
|
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-06-04 00:05:06 +02:00
|
|
|
try:
|
|
|
|
import lister
|
|
|
|
except ImportError as e:
|
|
|
|
print("ImportError: {}".format(e))
|
|
|
|
print("You need to run the Zulip linters inside a Zulip dev environment.")
|
|
|
|
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
|
|
|
|
sys.exit(1)
|
2016-03-22 21:20:33 +01:00
|
|
|
|
2013-02-19 04:40:57 +01:00
|
|
|
parser = optparse.OptionParser()
|
|
|
|
parser.add_option('--full',
|
|
|
|
action='store_true',
|
|
|
|
help='Check some things we typically ignore')
|
2013-11-27 20:11:03 +01:00
|
|
|
parser.add_option('--modified', '-m',
|
|
|
|
action='store_true',
|
|
|
|
help='Only check modified files')
|
2016-05-04 23:21:37 +02:00
|
|
|
parser.add_option('--verbose', '-v',
|
|
|
|
action='store_true',
|
|
|
|
help='Print verbose timing output')
|
2013-02-19 04:40:57 +01:00
|
|
|
(options, args) = parser.parse_args()
|
2012-10-25 21:55:52 +02:00
|
|
|
|
2016-05-25 15:42:09 +02:00
|
|
|
os.chdir(os.path.join(os.path.dirname(__file__), '..'))
|
2012-10-04 20:30:01 +02:00
|
|
|
|
2012-10-04 21:27:52 +02:00
|
|
|
|
2013-02-19 04:40:57 +01:00
|
|
|
# Exclude some directories and files from lint checking
|
2012-10-20 03:00:05 +02:00
|
|
|
|
2016-03-22 21:20:33 +01:00
|
|
|
exclude = """
|
2013-07-25 22:41:44 +02:00
|
|
|
static/third
|
2015-10-13 23:34:50 +02:00
|
|
|
frontend_tests/casperjs
|
2013-07-29 23:03:31 +02:00
|
|
|
zerver/migrations
|
2013-03-26 16:20:06 +01:00
|
|
|
node_modules
|
2015-08-18 23:22:51 +02:00
|
|
|
docs/html_unescape.py
|
2013-08-06 22:51:47 +02:00
|
|
|
zproject/test_settings.py
|
2016-06-17 02:30:48 +02:00
|
|
|
zproject/dev_settings.py
|
2013-09-24 20:28:28 +02:00
|
|
|
zproject/settings.py
|
2013-02-19 04:40:57 +01:00
|
|
|
tools/jslint/jslint.js
|
2013-10-31 22:09:33 +01:00
|
|
|
api/setup.py
|
2013-12-05 22:54:43 +01:00
|
|
|
api/integrations/perforce/git_p4.py
|
2016-03-22 21:20:33 +01:00
|
|
|
puppet/apt/.forge-release
|
2016-04-05 02:08:23 +02:00
|
|
|
puppet/puppet-common/tests/
|
2016-04-14 23:29:58 +02:00
|
|
|
puppet/apt/README.md
|
2016-06-22 02:17:34 +02:00
|
|
|
static/locale
|
2013-02-19 04:40:57 +01:00
|
|
|
""".split()
|
2012-10-25 21:55:52 +02:00
|
|
|
|
2016-03-22 21:20:33 +01:00
|
|
|
by_lang = lister.list_files(args, modified_only=options.modified, use_shebang=True,
|
2016-04-14 23:34:04 +02:00
|
|
|
ftypes=['py', 'sh', 'js', 'pp', 'css', 'handlebars', 'html', 'json', 'md', 'txt', 'text'],
|
2016-04-14 23:29:58 +02:00
|
|
|
group_by_ftype=True, exclude=exclude)
|
2016-01-17 17:24:31 +01:00
|
|
|
|
2013-05-31 20:51:37 +02:00
|
|
|
# Invoke the appropriate lint checker for each language,
|
|
|
|
# and also check files for extra whitespace.
|
2013-02-19 04:40:57 +01:00
|
|
|
|
2013-07-18 23:38:15 +02:00
|
|
|
import logging
|
|
|
|
logging.basicConfig(format="%(asctime)s %(message)s")
|
|
|
|
logger = logging.getLogger()
|
2016-05-04 23:21:37 +02:00
|
|
|
if options.verbose:
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
else:
|
|
|
|
logger.setLevel(logging.WARNING)
|
2013-07-18 23:38:15 +02:00
|
|
|
|
|
|
|
def check_pyflakes():
|
2016-03-23 03:57:20 +01:00
|
|
|
if not by_lang['py']:
|
2013-11-27 19:30:44 +01:00
|
|
|
return False
|
2013-02-19 04:40:57 +01:00
|
|
|
failed = False
|
2016-03-23 03:57:20 +01:00
|
|
|
pyflakes = subprocess.Popen(['pyflakes'] + by_lang['py'],
|
2013-07-18 23:38:15 +02:00
|
|
|
stdout = subprocess.PIPE,
|
2016-05-25 15:53:13 +02:00
|
|
|
stderr = subprocess.PIPE,
|
|
|
|
universal_newlines = True)
|
2013-02-19 04:40:57 +01:00
|
|
|
|
2013-07-18 23:38:15 +02:00
|
|
|
# pyflakes writes some output (like syntax errors) to stderr. :/
|
|
|
|
for pipe in (pyflakes.stdout, pyflakes.stderr):
|
|
|
|
for ln in pipe:
|
|
|
|
if options.full or not \
|
|
|
|
('imported but unused' in ln or
|
2013-11-13 03:34:28 +01:00
|
|
|
'redefinition of unused' in ln or
|
2013-08-09 19:15:44 +02:00
|
|
|
("zerver/models.py" in ln and
|
|
|
|
" undefined name 'bugdown'" in ln) or
|
2016-03-11 09:26:44 +01:00
|
|
|
("scripts/lib/pythonrc.py" in ln and
|
|
|
|
" import *' used; unable to detect undefined names" in ln) or
|
2014-01-14 17:39:18 +01:00
|
|
|
("zerver/lib/tornado_ioloop_logging.py" in ln and
|
|
|
|
"redefinition of function 'instrument_tornado_ioloop'" in ln) or
|
2013-07-18 23:38:15 +02:00
|
|
|
("zephyr_mirror_backend.py:" in ln and
|
|
|
|
"redefinition of unused 'simplejson' from line" in ln)):
|
|
|
|
sys.stdout.write(ln)
|
|
|
|
failed = True
|
|
|
|
return failed
|
2013-02-19 04:40:57 +01:00
|
|
|
|
2016-06-03 01:04:39 +02:00
|
|
|
def custom_check_file(fn, rules, skip_rules=None):
|
2015-12-05 22:47:50 +01:00
|
|
|
failed = False
|
2016-03-16 19:39:12 +01:00
|
|
|
lineFlag = False
|
2015-12-05 22:47:50 +01:00
|
|
|
for i, line in enumerate(open(fn)):
|
2016-06-17 19:41:39 +02:00
|
|
|
line_newline_stripped = line.strip('\n')
|
|
|
|
line_fully_stripped = line_newline_stripped.strip()
|
2015-12-05 22:47:50 +01:00
|
|
|
skip = False
|
2016-03-16 19:39:12 +01:00
|
|
|
lineFlag = True
|
2016-06-03 01:04:39 +02:00
|
|
|
for rule in skip_rules or []:
|
2015-12-05 22:47:50 +01:00
|
|
|
if re.match(rule, line):
|
|
|
|
skip = True
|
|
|
|
if skip:
|
|
|
|
continue
|
|
|
|
for rule in rules:
|
2015-12-05 22:56:27 +01:00
|
|
|
exclude_list = rule.get('exclude', set())
|
|
|
|
if fn in exclude_list:
|
|
|
|
continue
|
2016-05-27 11:49:46 +02:00
|
|
|
exclude_list = rule.get('exclude_line', set())
|
2016-06-17 19:41:39 +02:00
|
|
|
if (fn, line_fully_stripped) in exclude_list:
|
2016-05-27 11:49:46 +02:00
|
|
|
continue
|
2015-12-05 22:47:50 +01:00
|
|
|
try:
|
2016-06-17 19:41:39 +02:00
|
|
|
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):
|
2015-12-05 22:47:50 +01:00
|
|
|
sys.stdout.write(rule['description'] + ' at %s line %s:\n' % (fn, i+1))
|
2016-03-10 17:15:34 +01:00
|
|
|
print(line)
|
2015-12-05 22:47:50 +01:00
|
|
|
failed = True
|
|
|
|
except Exception:
|
2016-03-10 17:15:34 +01:00
|
|
|
print("Exception with %s at %s line %s" % (rule['pattern'], fn, i+1))
|
2015-12-05 22:47:50 +01:00
|
|
|
traceback.print_exc()
|
2016-03-16 19:39:12 +01:00
|
|
|
lastLine = line
|
|
|
|
if lineFlag and '\n' not in lastLine:
|
2016-04-14 19:50:53 +02:00
|
|
|
print("No newline at the end of file. Fix with `sed -i '$a\\' %s`" % (fn,))
|
2016-03-16 19:39:12 +01:00
|
|
|
failed = True
|
2015-12-05 22:47:50 +01:00
|
|
|
return failed
|
|
|
|
|
|
|
|
whitespace_rules = [
|
2016-04-08 20:50:14 +02:00
|
|
|
# This linter should be first since bash_rules depends on it.
|
2015-12-05 22:47:50 +01:00
|
|
|
{'pattern': '\s+$',
|
|
|
|
'strip': '\n',
|
|
|
|
'description': 'Fix trailing whitespace'},
|
|
|
|
{'pattern': '\t',
|
|
|
|
'strip': '\n',
|
2015-12-05 22:56:27 +01:00
|
|
|
'exclude': set(['zerver/lib/bugdown/codehilite.py']),
|
2015-12-05 22:47:50 +01:00
|
|
|
'description': 'Fix tab-based whitespace'},
|
|
|
|
]
|
|
|
|
js_rules = [
|
|
|
|
{'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'},
|
2015-12-05 22:56:27 +01:00
|
|
|
{'pattern': '[)]{$',
|
|
|
|
'description': 'Missing space between ) and {'},
|
2016-06-09 20:59:40 +02:00
|
|
|
{'pattern': '["\']json/',
|
|
|
|
'description': 'Relative URL for JSON route not supported by i18n'},
|
2016-04-20 20:32:57 +02:00
|
|
|
# This rule is constructed with + to avoid triggering on itself
|
2016-04-20 20:36:09 +02:00
|
|
|
{'pattern': " =" + '[^ =>~"]',
|
|
|
|
'description': 'Missing whitespace after "="'},
|
2016-06-09 22:44:24 +02:00
|
|
|
{'pattern': '^[ ]*//[A-Za-z0-9]',
|
|
|
|
'description': 'Missing space after // in comment'},
|
2016-06-09 22:47:12 +02:00
|
|
|
{'pattern': 'if[(]',
|
|
|
|
'description': 'Missing space between if and ('},
|
2015-12-05 22:56:27 +01:00
|
|
|
{'pattern': 'else{$',
|
|
|
|
'description': 'Missing space between else and {'},
|
2016-06-09 23:02:49 +02:00
|
|
|
{'pattern': '^else {$',
|
|
|
|
'description': 'Write JS else statements on same line as }'},
|
2016-06-09 23:05:34 +02:00
|
|
|
{'pattern': '^else if',
|
|
|
|
'description': 'Write JS else statements on same line as }'},
|
2016-06-13 10:23:20 +02:00
|
|
|
{'pattern': 'button\.text\(["\']',
|
|
|
|
'exclude': set(['tools/lint-all',
|
|
|
|
'frontend_tests/node_tests/templates.js']),
|
|
|
|
'description': 'Argument to button.text should be a literal string enclosed by i18n.t()'},
|
|
|
|
{'pattern': 'compose_error\(["\']',
|
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
'description': 'Argument to compose_error should be a literal string enclosed '
|
|
|
|
'by i18n.t()'},
|
2015-12-05 22:56:27 +01:00
|
|
|
] + whitespace_rules
|
2015-12-05 22:47:50 +01:00
|
|
|
python_rules = [
|
2016-04-21 23:48:34 +02:00
|
|
|
{'pattern': '^(?!#)@login_required',
|
|
|
|
'description': '@login_required is unsupported; use @zulip_login_required'},
|
2015-12-05 22:59:56 +01:00
|
|
|
{'pattern': '".*"%\([a-z_].*\)?$',
|
|
|
|
'description': 'Missing space around "%"'},
|
|
|
|
{'pattern': "'.*'%\([a-z_].*\)?$",
|
2016-05-27 13:14:40 +02:00
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
'exclude_line': set([
|
|
|
|
('zerver/views/users.py',
|
|
|
|
"return json_error(_(\"Email '%(email)s' does not belong to domain '%(domain)s'\") %"),
|
|
|
|
]),
|
2015-12-05 22:56:27 +01:00
|
|
|
'description': 'Missing space around "%"'},
|
2016-04-20 20:32:57 +02:00
|
|
|
# This rule is constructed with + to avoid triggering on itself
|
|
|
|
{'pattern': " =" + '[^ =>~"]',
|
|
|
|
'description': 'Missing whitespace after "="'},
|
2016-04-28 07:20:58 +02:00
|
|
|
{'pattern': '":\w[^"]*$',
|
|
|
|
'description': 'Missing whitespace after ":"'},
|
|
|
|
{'pattern': "':\w[^']*$",
|
|
|
|
'description': 'Missing whitespace after ":"'},
|
2016-05-03 07:09:24 +02:00
|
|
|
{'pattern': "^\s+[#]\w",
|
|
|
|
'strip': '\n',
|
|
|
|
'description': 'Missing whitespace after "#"'},
|
2016-05-31 15:58:35 +02:00
|
|
|
{'pattern': "== None",
|
|
|
|
'exclude': 'tools/lint-all',
|
|
|
|
'description': 'Use `is None` to check whether something is None'},
|
2016-06-05 22:00:55 +02:00
|
|
|
{'pattern': "type:[(]",
|
|
|
|
'description': 'Missing whitespace after ":" in type annotation'},
|
|
|
|
{'pattern': "#type",
|
|
|
|
'exclude': 'tools/lint-all',
|
|
|
|
'description': 'Missing whitespace after "#" in type annotation'},
|
2016-05-04 23:14:13 +02:00
|
|
|
{'pattern': ", [)]",
|
|
|
|
'description': 'Unnecessary whitespace between "," and ")"'},
|
2016-05-04 23:19:50 +02:00
|
|
|
{'pattern': "% [(]",
|
|
|
|
'description': 'Unnecessary whitespace between "%" and "("'},
|
2015-12-05 22:56:27 +01:00
|
|
|
# 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.
|
2016-01-27 05:12:06 +01:00
|
|
|
{'pattern': '% [a-zA-Z0-9_.]*\)?$',
|
2015-12-05 22:47:50 +01:00
|
|
|
'description': 'Used % comprehension without a tuple'},
|
2016-05-27 13:14:40 +02:00
|
|
|
# To avoid json_error(_variable) and json_error(_(variable))
|
|
|
|
{'pattern': '\Wjson_error\(_\(?\w+\)',
|
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
'description': 'Argument to json_error should be a literal string enclosed by _()'},
|
|
|
|
{'pattern': '\Wjson_error\([^_].+\)',
|
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
'exclude_line': set([
|
|
|
|
# function definition
|
2016-06-03 01:04:39 +02:00
|
|
|
('zerver/lib/response.py', 'def json_error(msg, data=None, status=400):'),
|
2016-05-27 13:14:40 +02:00
|
|
|
# No need to worry about the following as the translation strings
|
|
|
|
# are already captured
|
|
|
|
('zerver/middleware.py',
|
|
|
|
'return json_error(exception.to_json_error_msg(), status=status_code)'),
|
|
|
|
('zerver/tornadoviews.py', 'return json_error(result["message"])'),
|
|
|
|
('zerver/views/__init__.py',
|
|
|
|
'return json_error(data=error_data, msg=ret_error)'),
|
|
|
|
('zerver/views/streams.py', 'return json_error(property_conversion)'),
|
|
|
|
# We can't do anything about this.
|
2016-06-04 08:02:40 +02:00
|
|
|
('zerver/views/realm_emoji.py', 'return json_error(e.messages[0])'),
|
2016-05-27 13:14:40 +02:00
|
|
|
]),
|
|
|
|
'description': 'Argument to json_error should a literal string enclosed by _()'},
|
|
|
|
# To avoid JsonableError(_variable) and JsonableError(_(variable))
|
|
|
|
{'pattern': '\WJsonableError\(_\(?\w.+\)',
|
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
'description': 'Argument to JsonableError should be a literal string enclosed by _()'},
|
|
|
|
{'pattern': '\WJsonableError\([^_].+\)',
|
|
|
|
'exclude': set(['tools/lint-all']),
|
|
|
|
'exclude_line': set([
|
|
|
|
# class definition
|
|
|
|
('zerver/lib/request.py', 'class JsonableError(Exception):'),
|
|
|
|
# No need to worry about the following as the translation strings
|
|
|
|
# are already captured
|
|
|
|
('zerver/decorator.py', 'raise JsonableError(reason % (role,))'),
|
|
|
|
('zerver/lib/actions.py', 'raise JsonableError(e.messages[0])'),
|
|
|
|
('zerver/views/messages.py', 'raise JsonableError(error)'),
|
|
|
|
('zerver/lib/request.py', 'raise JsonableError(error)'),
|
|
|
|
]),
|
|
|
|
'description': 'Argument to JsonableError should be a literal string enclosed by _()'},
|
2016-06-16 09:40:25 +02:00
|
|
|
{'pattern': '([a-zA-Z0-9_]+)=REQ\([\'"]\\1[\'"]',
|
|
|
|
'description': 'REQ\'s first argument already defaults to parameter name'},
|
2015-12-05 22:56:27 +01:00
|
|
|
] + whitespace_rules
|
2016-01-17 17:24:31 +01:00
|
|
|
bash_rules = [
|
|
|
|
{'pattern': '#!.*sh [-xe]',
|
|
|
|
'description': 'Fix shebang line with proper call to /usr/bin/env for Bash path, change -x|-e switches to set -x|set -e'},
|
2016-04-08 20:49:05 +02:00
|
|
|
] + whitespace_rules[0:1]
|
2016-04-09 05:56:46 +02:00
|
|
|
css_rules = [
|
|
|
|
{'pattern': '^[^:]*:\S[^:]*;$',
|
|
|
|
'description': "Missing whitespace after : in CSS"},
|
2016-04-20 20:50:01 +02:00
|
|
|
{'pattern': '{\w',
|
|
|
|
'description': "Missing whitespace after '{' in CSS (should be newline)."},
|
2016-04-09 05:56:46 +02:00
|
|
|
] + whitespace_rules
|
2016-04-08 20:45:47 +02:00
|
|
|
handlebars_rules = whitespace_rules
|
2016-06-13 10:23:20 +02:00
|
|
|
html_rules = whitespace_rules + [
|
|
|
|
{'pattern': 'placeholder="[^{]',
|
|
|
|
'description': "`placeholder` value should be translatable."},
|
|
|
|
{'pattern': "placeholder='[^{]",
|
|
|
|
'description': "`placeholder` value should be translatable."},
|
|
|
|
]
|
2016-04-14 19:48:30 +02:00
|
|
|
json_rules = [] # just fix newlines at ends of files
|
2016-04-14 23:29:58 +02:00
|
|
|
markdown_rules = whitespace_rules
|
2016-04-14 23:34:04 +02:00
|
|
|
txt_rules = whitespace_rules
|
2015-12-05 22:47:50 +01:00
|
|
|
|
2016-06-17 19:26:48 +02:00
|
|
|
def check_custom_checks_py():
|
2013-07-18 23:38:15 +02:00
|
|
|
failed = False
|
2013-02-19 04:40:57 +01:00
|
|
|
|
2016-03-23 03:57:20 +01:00
|
|
|
for fn in by_lang['py']:
|
2016-04-08 20:36:08 +02:00
|
|
|
if custom_check_file(fn, python_rules):
|
2013-06-27 20:03:28 +02:00
|
|
|
failed = True
|
2016-06-17 19:26:48 +02:00
|
|
|
return failed
|
|
|
|
|
|
|
|
def check_custom_checks_nonpy():
|
|
|
|
failed = False
|
2013-06-27 20:03:28 +02:00
|
|
|
|
2016-03-23 03:57:20 +01:00
|
|
|
for fn in by_lang['js']:
|
2015-12-05 22:47:50 +01:00
|
|
|
if custom_check_file(fn, js_rules):
|
2013-07-05 18:53:43 +02:00
|
|
|
failed = True
|
|
|
|
|
2016-03-23 03:57:20 +01:00
|
|
|
for fn in by_lang['sh']:
|
2016-01-17 17:24:31 +01:00
|
|
|
if custom_check_file(fn, bash_rules):
|
|
|
|
failed = True
|
|
|
|
|
2016-04-08 20:38:25 +02:00
|
|
|
for fn in by_lang['css']:
|
|
|
|
if custom_check_file(fn, css_rules):
|
|
|
|
failed = True
|
|
|
|
|
2016-04-08 20:45:47 +02:00
|
|
|
for fn in by_lang['handlebars']:
|
|
|
|
if custom_check_file(fn, handlebars_rules):
|
|
|
|
failed = True
|
|
|
|
|
2016-04-08 20:44:39 +02:00
|
|
|
for fn in by_lang['html']:
|
|
|
|
if custom_check_file(fn, html_rules):
|
|
|
|
failed = True
|
|
|
|
|
2016-04-14 19:48:30 +02:00
|
|
|
for fn in by_lang['json']:
|
|
|
|
if custom_check_file(fn, json_rules):
|
|
|
|
failed = True
|
|
|
|
|
2016-04-14 23:29:58 +02:00
|
|
|
for fn in by_lang['md']:
|
|
|
|
if custom_check_file(fn, markdown_rules):
|
|
|
|
failed = True
|
|
|
|
|
2016-04-14 23:34:04 +02:00
|
|
|
for fn in by_lang['txt'] + by_lang['text']:
|
|
|
|
if custom_check_file(fn, txt_rules):
|
|
|
|
failed = True
|
|
|
|
|
2013-07-18 23:38:15 +02:00
|
|
|
return failed
|
2013-03-25 23:44:38 +01:00
|
|
|
|
2013-11-27 19:00:08 +01:00
|
|
|
lint_functions = {}
|
|
|
|
|
|
|
|
def run_parallel():
|
|
|
|
pids = []
|
|
|
|
for name, func in lint_functions.items():
|
|
|
|
pid = os.fork()
|
|
|
|
if pid == 0:
|
|
|
|
logging.info("start " + name)
|
|
|
|
result = func()
|
|
|
|
logging.info("finish " + name)
|
|
|
|
os._exit(result)
|
|
|
|
pids.append(pid)
|
2013-07-18 23:38:15 +02:00
|
|
|
failed = False
|
|
|
|
|
2013-11-27 19:00:08 +01:00
|
|
|
for pid in pids:
|
|
|
|
(_, status) = os.waitpid(pid, 0)
|
|
|
|
if status != 0:
|
|
|
|
failed = True
|
|
|
|
return failed
|
|
|
|
|
|
|
|
def lint(func):
|
|
|
|
lint_functions[func.__name__] = func
|
|
|
|
return func
|
|
|
|
|
|
|
|
try:
|
2013-07-18 23:38:15 +02:00
|
|
|
# Make the lint output bright red
|
|
|
|
sys.stdout.write('\x1B[1;31m')
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2013-11-27 19:00:08 +01:00
|
|
|
@lint
|
|
|
|
def templates():
|
2013-12-17 18:44:59 +01:00
|
|
|
result = subprocess.call(['tools/check-templates'])
|
2013-11-27 19:00:08 +01:00
|
|
|
return result
|
2013-10-08 14:31:16 +02:00
|
|
|
|
2013-11-27 19:00:08 +01:00
|
|
|
@lint
|
|
|
|
def jslint():
|
2013-07-19 17:41:00 +02:00
|
|
|
result = subprocess.call(['tools/node', 'tools/jslint/check-all.js']
|
2016-03-23 03:57:20 +01:00
|
|
|
+ by_lang['js'])
|
2013-11-27 19:00:08 +01:00
|
|
|
return result
|
2013-07-18 23:38:15 +02:00
|
|
|
|
2013-11-27 19:00:08 +01:00
|
|
|
@lint
|
|
|
|
def puppet():
|
2016-03-23 03:57:20 +01:00
|
|
|
if not by_lang['pp']:
|
2013-11-27 19:30:44 +01:00
|
|
|
return 0
|
2016-03-23 03:57:20 +01:00
|
|
|
result = subprocess.call(['puppet', 'parser', 'validate'] + by_lang['pp'])
|
2013-11-27 19:00:08 +01:00
|
|
|
return result
|
2013-08-08 22:06:26 +02:00
|
|
|
|
2013-11-27 19:00:08 +01:00
|
|
|
@lint
|
2016-06-17 19:26:48 +02:00
|
|
|
def custom_py():
|
|
|
|
failed = check_custom_checks_py()
|
|
|
|
return 1 if failed else 0
|
|
|
|
|
|
|
|
@lint
|
|
|
|
def custom_nonpy():
|
|
|
|
failed = check_custom_checks_nonpy()
|
2013-11-27 19:00:08 +01:00
|
|
|
return 1 if failed else 0
|
2013-07-18 23:38:15 +02:00
|
|
|
|
2013-11-27 19:00:08 +01:00
|
|
|
@lint
|
|
|
|
def pyflakes():
|
2013-09-19 16:39:51 +02:00
|
|
|
failed = check_pyflakes()
|
2013-11-27 19:00:08 +01:00
|
|
|
return 1 if failed else 0
|
2013-09-19 16:39:51 +02:00
|
|
|
|
2013-11-27 19:00:08 +01:00
|
|
|
failed = run_parallel()
|
2013-09-19 16:43:24 +02:00
|
|
|
|
2013-02-19 04:40:57 +01:00
|
|
|
sys.exit(1 if failed else 0)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
# Restore normal terminal colors
|
|
|
|
sys.stdout.write('\x1B[0m')
|