summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-01-29 12:28:51 +0000
committerGerrit Code Review <review@openstack.org>2016-01-29 12:28:51 +0000
commit4ef0e117d8d64e4127041dd724e1df8b49de2583 (patch)
tree71597ae1e7b8f0b6037b46c490aa12d1a9dab634
parent6e581553a4a511f77129ac870a4b15a3cd02b0b7 (diff)
parenta96c31fb3ebfda69bd4149aff6dbcf2d0013dd3e (diff)
Merge "Skip long line check for rst definition list term"0.7.0
-rw-r--r--doc8/checks.py18
-rw-r--r--doc8/tests/test_checks.py17
2 files changed, 35 insertions, 0 deletions
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):
206 directives.append((i, find_directive_end(i, lines))) 206 directives.append((i, find_directive_end(i, lines)))
207 elif re.match(r"^::\s*$", line): 207 elif re.match(r"^::\s*$", line):
208 directives.append((i, find_directive_end(i, lines))) 208 directives.append((i, find_directive_end(i, lines)))
209
210 # Find definition terms in definition lists
211 # This check may match the code, which is already appended
212 lwhitespaces = r"^\s*"
213 listspattern = r"^\s*(\* |- |#\. |\d+\. )"
214 for i in range(0, len(lines) - 1):
215 line = lines[i]
216 next_line = lines[i + 1]
217 # if line is a blank, line is not a definition term
218 if all_whitespace(line):
219 continue
220 # if line is a list, line is checked as normal line
221 if re.match(listspattern, line):
222 continue
223 if (len(re.search(lwhitespaces, line).group()) <
224 len(re.search(lwhitespaces, next_line).group())):
225 directives.append((i, i))
226
209 return directives 227 return directives
210 228
211 def _txt_checker(self, parsed_file): 229 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
156 errors = list(check.report_iter(parsed_file)) 156 errors = list(check.report_iter(parsed_file))
157 self.assertEqual(expected_errors, len(errors)) 157 self.assertEqual(expected_errors, len(errors))
158 158
159 def test_definition_term_length(self):
160 conf = {
161 'max_line_length': 79,
162 'allow_long_titles': True,
163 }
164 with tempfile.NamedTemporaryFile(suffix='.rst') as fh:
165 fh.write(b'Definition List which contains long term.\n\n'
166 b'looooooooooooooooooooooooooooooong definition term'
167 b'this line exceeds 80 chars but should be ignored\n'
168 b' this is a definition\n')
169 fh.flush()
170
171 parsed_file = parser.ParsedFile(fh.name, encoding='utf-8')
172 check = checks.CheckMaxLineLength(conf)
173 errors = list(check.report_iter(parsed_file))
174 self.assertEqual(0, len(errors))
175
159 176
160class TestNewlineEndOfFile(testtools.TestCase): 177class TestNewlineEndOfFile(testtools.TestCase):
161 def test_newline(self): 178 def test_newline(self):