|
93 | 93 | "GL07": "Sections are in the wrong order. Correct order is: " "{correct_sections}",
|
94 | 94 | "GL08": "The object does not have a docstring",
|
95 | 95 | "GL09": "Deprecation warning should precede extended summary",
|
| 96 | + "GL10": "reST directives {directives} must be followed by two colons", |
96 | 97 | "SS01": "No summary found (a short summary in a single line should be "
|
97 | 98 | "present at the beginning of the docstring)",
|
98 | 99 | "SS02": "Summary does not start with a capital letter",
|
@@ -239,6 +240,10 @@ def get_api_items(api_doc_fd):
|
239 | 240 |
|
240 | 241 |
|
241 | 242 | class Docstring:
|
| 243 | + DIRECTIVES = ['deprecated', 'versionadded', 'versionchanged'] |
| 244 | + DIRECTIVE_WITHOUT_TWO_COLONS = re.compile( |
| 245 | + rf"^\s*.. ({'|'.join(DIRECTIVES)})(?!::)", re.I | re.M) |
| 246 | + |
242 | 247 | def __init__(self, name):
|
243 | 248 | self.name = name
|
244 | 249 | obj = self._load_obj(name)
|
@@ -478,6 +483,10 @@ def parameter_mismatches(self):
|
478 | 483 | def correct_parameters(self):
|
479 | 484 | return not bool(self.parameter_mismatches)
|
480 | 485 |
|
| 486 | + @property |
| 487 | + def directives_without_two_colons(self): |
| 488 | + return Docstring.DIRECTIVE_WITHOUT_TWO_COLONS.findall(self.raw_doc) |
| 489 | + |
481 | 490 | def parameter_type(self, param):
|
482 | 491 | return self.doc_parameters[param][0]
|
483 | 492 |
|
@@ -697,6 +706,10 @@ def get_validation_data(doc):
|
697 | 706 | if doc.deprecated and not doc.extended_summary.startswith(".. deprecated:: "):
|
698 | 707 | errs.append(error("GL09"))
|
699 | 708 |
|
| 709 | + directives_without_two_colons = doc.directives_without_two_colons |
| 710 | + if directives_without_two_colons: |
| 711 | + errs.append(error("GL10", directives=directives_without_two_colons)) |
| 712 | + |
700 | 713 | if not doc.summary:
|
701 | 714 | errs.append(error("SS01"))
|
702 | 715 | else:
|
|
0 commit comments