diff --git a/tools/check-templates b/tools/check-templates index 8d3e8d858b..d1ad1d3512 100755 --- a/tools/check-templates +++ b/tools/check-templates @@ -85,7 +85,7 @@ def check_html_templates(templates, modified_only): 'templates/zerver/right-sidebar.html', 'templates/zerver/search_operators.html', ] - validate(fn, check_indent=(fn not in bad_files)) + validate(fn=fn, check_indent=(fn not in bad_files)) def check_handlebar_templates(templates, modified_only): # type: (Iterable[str], bool) -> None @@ -94,7 +94,7 @@ def check_handlebar_templates(templates, modified_only): if not modified_only: assert len(templates) >= 10 # sanity check that we are actually doing work for fn in templates: - validate(fn, check_indent=True) + validate(fn=fn, check_indent=True) if __name__ == '__main__': check_our_files() diff --git a/tools/lib/template_parser.py b/tools/lib/template_parser.py index 7b6095a8fc..2e83717351 100644 --- a/tools/lib/template_parser.py +++ b/tools/lib/template_parser.py @@ -103,9 +103,16 @@ def tokenize(text): return tokens -def validate(fn, check_indent=True): - # type: (str, bool) -> None - text = open(fn).read() +def validate(fn=None, text=None, check_indent=True): + # type: (str, str, bool) -> None + assert fn or text + + if fn is None: + fn = '' + + if text is None: + text = open(fn).read() + tokens = tokenize(text) class State(object):