diff --git a/doc8/checks.py b/doc8/checks.py index 993183f..cf3a06d 100644 --- a/doc8/checks.py +++ b/doc8/checks.py @@ -206,6 +206,24 @@ class CheckMaxLineLength(ContentCheck): directives.append((i, find_directive_end(i, lines))) elif re.match(r"^::\s*$", line): 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 def _txt_checker(self, parsed_file): diff --git a/doc8/tests/test_checks.py b/doc8/tests/test_checks.py index 0011d79..af32c05 100644 --- a/doc8/tests/test_checks.py +++ b/doc8/tests/test_checks.py @@ -156,6 +156,23 @@ test errors = list(check.report_iter(parsed_file)) 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): def test_newline(self):