lint: Enforce that code blocks can't split lines.

Fixes: #1644.
This commit is contained in:
Steve Howell 2016-08-18 07:02:18 -07:00 committed by Tim Abbott
parent 479aa5b83d
commit 88a7ea54d2
2 changed files with 27 additions and 0 deletions

View File

@ -154,6 +154,8 @@ def validate(fn=None, text=None, check_indent=True):
end_col = end_token.col
problem = None
if (start_tag == 'code') and (end_line == start_line + 1):
problem = 'Code tag is split across two lines.'
if start_tag != end_tag:
problem = 'Mismatched tag.'
elif check_indent and end_line > start_line + 1 and end_col != start_col:

View File

@ -54,6 +54,31 @@ class ParserTest(unittest.TestCase):
'''
validate(text=my_html)
def test_code_blocks(self):
# type: () -> None
# This is fine.
my_html = '''
<code>
x = 5
y = x + 1
</code>'''
validate(text=my_html)
# This is also fine.
my_html = "<code>process_widgets()</code>"
validate(text=my_html)
# This is illegal.
my_html = '''
<code>x =
5</code>
'''
# See https://github.com/python/typeshed/issues/372
# for why we have to ingore types here.
with self.assertRaisesRegexp(Exception, 'split across two lines'): # type: ignore
validate(text=my_html)
def test_tokenize(self):
# type: () -> None
tag = '<meta whatever>bla'