summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKATO Tomoyuki <kato.tomoyuki@jp.fujitsu.com>2016-01-24 22:12:57 +0900
committerKATO Tomoyuki <kato.tomoyuki@jp.fujitsu.com>2016-01-26 12:37:05 +0900
commita96c31fb3ebfda69bd4149aff6dbcf2d0013dd3e (patch)
tree21f8ae714ecbba50fa71cb02c89c65b7e8aba799
parentb2c19dd214ad0d32e1bb4f6661e3f4226d5af776 (diff)
Skip long line check for rst definition list term
Notes
Notes (review): Code-Review+2: Joshua Harlow <harlowja@yahoo-inc.com> Code-Review+2: Christian Berendt <christian@berendt.io> Workflow+1: Christian Berendt <christian@berendt.io> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Fri, 29 Jan 2016 12:28:51 +0000 Reviewed-on: https://review.openstack.org/271757 Project: openstack/doc8 Branch: refs/heads/master
-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):