mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 03:11:54 +00:00
css linter: Report empty declarations more clearly.
Raise a CssParserException when declarations are empty.
This commit is contained in:
@@ -208,7 +208,11 @@ def parse_declaration_block(tokens):
|
|||||||
def parse_declaration(tokens):
|
def parse_declaration(tokens):
|
||||||
# type: (List[Token]) -> CssDeclaration
|
# type: (List[Token]) -> CssDeclaration
|
||||||
i, pre_fluff = get_whitespace_and_comments(tokens, 0)
|
i, pre_fluff = get_whitespace_and_comments(tokens, 0)
|
||||||
|
try:
|
||||||
css_property = tokens[i].s
|
css_property = tokens[i].s
|
||||||
|
except IndexError:
|
||||||
|
raise CssParserException('Empty declaration')
|
||||||
|
|
||||||
if tokens[i+1].s != ':':
|
if tokens[i+1].s != ':':
|
||||||
# print(css_property)
|
# print(css_property)
|
||||||
raise CssParserException('We expect a colon here')
|
raise CssParserException('We expect a colon here')
|
||||||
|
|||||||
@@ -62,6 +62,15 @@ class ParserTestHappyPath(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertFalse(section.declaration_block.declarations[0].semicolon)
|
self.assertFalse(section.declaration_block.declarations[0].semicolon)
|
||||||
|
|
||||||
|
def test_empty_block(self):
|
||||||
|
# type: () -> None
|
||||||
|
my_css = '''
|
||||||
|
div {
|
||||||
|
}'''
|
||||||
|
error = 'Empty declaration'
|
||||||
|
with self.assertRaisesRegexp(CssParserException, error): # type: ignore # See https://github.com/python/typeshed/issues/372
|
||||||
|
parse(my_css)
|
||||||
|
|
||||||
def test_multi_line_selector(self):
|
def test_multi_line_selector(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
my_css = '''
|
my_css = '''
|
||||||
|
|||||||
Reference in New Issue
Block a user