Browse Source

Fix issue of checking max_len for directives

This patch changes the regex to also match directives
which start with whitespace.

Closes-Bug: #1487302

Change-Id: I4c3168228164d865cc31dfd24160c41267aeb016
Sam Stoelinga 3 years ago
parent
commit
64f22e443f
2 changed files with 20 additions and 1 deletions
  1. 1
    1
      doc8/checks.py
  2. 19
    0
      doc8/tests/test_checks.py

+ 1
- 1
doc8/checks.py View File

@@ -202,7 +202,7 @@ class CheckMaxLineLength(ContentCheck):
202 202
         # for unknown directives, so we have to do it manually).
203 203
         directives = []
204 204
         for i, line in enumerate(lines):
205
-            if re.match(r"^..\s(.*?)::\s*", line):
205
+            if re.match(r"^\s*..\s(.*?)::\s*", line):
206 206
                 directives.append((i, find_directive_end(i, lines)))
207 207
             elif re.match(r"^::\s*$", line):
208 208
                 directives.append((i, find_directive_end(i, lines)))

+ 19
- 0
doc8/tests/test_checks.py View File

@@ -105,6 +105,25 @@ test
105 105
             errors = list(check.report_iter(parsed_file))
106 106
             self.assertEqual(0, len(errors))
107 107
 
108
+    def test_ignore_code_block(self):
109
+        conf = {
110
+            'max_line_length': 79,
111
+            'allow_long_titles': True,
112
+        }
113
+        with tempfile.NamedTemporaryFile(suffix='.rst') as fh:
114
+            fh.write(b'List which contains items with code-block\n'
115
+                     b'- this is a list item\n\n'
116
+                     b'  .. code-block:: ini\n\n'
117
+                     b'     this line exceeds 80 chars but should be ignored'
118
+                     b'this line exceeds 80 chars but should be ignored'
119
+                     b'this line exceeds 80 chars but should be ignored')
120
+            fh.flush()
121
+
122
+            parsed_file = parser.ParsedFile(fh.name, encoding='utf-8')
123
+            check = checks.CheckMaxLineLength(conf)
124
+            errors = list(check.report_iter(parsed_file))
125
+            self.assertEqual(0, len(errors))
126
+
108 127
     def test_unsplittable_length(self):
109 128
         content = b"""
110 129
 ===

Loading…
Cancel
Save