Skip long line check for rst definition list term
Change-Id: Ieb272e506034eac7129c24ee0e0fbc40b55d11b1 Closes-Bug: #1533238
This commit is contained in:
parent
b2c19dd214
commit
a96c31fb3e
|
@ -206,6 +206,24 @@ class CheckMaxLineLength(ContentCheck):
|
||||||
directives.append((i, find_directive_end(i, lines)))
|
directives.append((i, find_directive_end(i, lines)))
|
||||||
elif re.match(r"^::\s*$", line):
|
elif re.match(r"^::\s*$", line):
|
||||||
directives.append((i, find_directive_end(i, lines)))
|
directives.append((i, find_directive_end(i, lines)))
|
||||||
|
|
||||||
|
# Find definition terms in definition lists
|
||||||
|
# This check may match the code, which is already appended
|
||||||
|
lwhitespaces = r"^\s*"
|
||||||
|
listspattern = r"^\s*(\* |- |#\. |\d+\. )"
|
||||||
|
for i in range(0, len(lines) - 1):
|
||||||
|
line = lines[i]
|
||||||
|
next_line = lines[i + 1]
|
||||||
|
# if line is a blank, line is not a definition term
|
||||||
|
if all_whitespace(line):
|
||||||
|
continue
|
||||||
|
# if line is a list, line is checked as normal line
|
||||||
|
if re.match(listspattern, line):
|
||||||
|
continue
|
||||||
|
if (len(re.search(lwhitespaces, line).group()) <
|
||||||
|
len(re.search(lwhitespaces, next_line).group())):
|
||||||
|
directives.append((i, i))
|
||||||
|
|
||||||
return directives
|
return directives
|
||||||
|
|
||||||
def _txt_checker(self, parsed_file):
|
def _txt_checker(self, parsed_file):
|
||||||
|
|
|
@ -156,6 +156,23 @@ test
|
||||||
errors = list(check.report_iter(parsed_file))
|
errors = list(check.report_iter(parsed_file))
|
||||||
self.assertEqual(expected_errors, len(errors))
|
self.assertEqual(expected_errors, len(errors))
|
||||||
|
|
||||||
|
def test_definition_term_length(self):
|
||||||
|
conf = {
|
||||||
|
'max_line_length': 79,
|
||||||
|
'allow_long_titles': True,
|
||||||
|
}
|
||||||
|
with tempfile.NamedTemporaryFile(suffix='.rst') as fh:
|
||||||
|
fh.write(b'Definition List which contains long term.\n\n'
|
||||||
|
b'looooooooooooooooooooooooooooooong definition term'
|
||||||
|
b'this line exceeds 80 chars but should be ignored\n'
|
||||||
|
b' this is a definition\n')
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
||||||
class TestNewlineEndOfFile(testtools.TestCase):
|
class TestNewlineEndOfFile(testtools.TestCase):
|
||||||
def test_newline(self):
|
def test_newline(self):
|
||||||
|
|
Loading…
Reference in New Issue