From bccc2998efe0decd4f8fbcea9cb19963f6586ddf Mon Sep 17 00:00:00 2001 From: KATO Tomoyuki Date: Sun, 24 Jan 2016 22:12:57 +0900 Subject: [PATCH] Skip long line check for rst definition list term The definition list term cannot have more than one line of text. On the other hand, we sometimes need to use the long term in the definition lists. This change skips "D001 Line too long" check for the definition terms in the definition lists. Change-Id: Ieb272e506034eac7129c24ee0e0fbc40b55d11b1 Closes-Bug: #1533238 --- doc8/checks.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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):