Fix issue of checking max_len for directives

This patch changes the regex to also match directives
which start with whitespace.

Closes-Bug: #1487302

Change-Id: I4c3168228164d865cc31dfd24160c41267aeb016
This commit is contained in:
Sam Stoelinga 2015-08-21 23:16:53 +08:00
parent 062bf244b6
commit 64f22e443f
2 changed files with 20 additions and 1 deletions

View File

@ -202,7 +202,7 @@ class CheckMaxLineLength(ContentCheck):
# for unknown directives, so we have to do it manually).
directives = []
for i, line in enumerate(lines):
if re.match(r"^..\s(.*?)::\s*", line):
if re.match(r"^\s*..\s(.*?)::\s*", line):
directives.append((i, find_directive_end(i, lines)))
elif re.match(r"^::\s*$", line):
directives.append((i, find_directive_end(i, lines)))

View File

@ -105,6 +105,25 @@ test
errors = list(check.report_iter(parsed_file))
self.assertEqual(0, len(errors))
def test_ignore_code_block(self):
conf = {
'max_line_length': 79,
'allow_long_titles': True,
}
with tempfile.NamedTemporaryFile(suffix='.rst') as fh:
fh.write(b'List which contains items with code-block\n'
b'- this is a list item\n\n'
b' .. code-block:: ini\n\n'
b' this line exceeds 80 chars but should be ignored'
b'this line exceeds 80 chars but should be ignored'
b'this line exceeds 80 chars but should be ignored')
fh.flush()
parsed_file = parser.ParsedFile(fh.name, encoding='utf-8')
check = checks.CheckMaxLineLength(conf)
errors = list(check.report_iter(parsed_file))
self.assertEqual(0, len(errors))
def test_unsplittable_length(self):
content = b"""
===