|
74 | 74 | 'whitespace only',
|
75 | 75 | 'GL06': 'Found unknown section "{section}". Allowed sections are: '
|
76 | 76 | '{allowed_sections}',
|
77 |
| - 'GL07': 'Wrong order of sections. "{wrong_section}" should be located ' |
78 |
| - 'before "{goes_before}", the right order is: {sorted_sections}', |
| 77 | + 'GL07': 'Sections are in the wrong order. Correct order is: ' |
| 78 | + '{correct_sections}', |
79 | 79 | 'SS01': 'No summary found (a short summary in a single line should be '
|
80 | 80 | 'present at the beginning of the docstring)',
|
81 | 81 | 'SS02': 'Summary does not start with a capital letter',
|
@@ -601,24 +601,18 @@ def validate_one(func_name):
|
601 | 601 | if re.match("^ *\t", line):
|
602 | 602 | errs.append(error('GL05', line_with_tabs=line.lstrip()))
|
603 | 603 |
|
604 |
| - unseen_sections = list(ALLOWED_SECTIONS) |
605 |
| - for section in doc.section_titles: |
606 |
| - if section not in ALLOWED_SECTIONS: |
607 |
| - errs.append(error('GL06', |
608 |
| - section=section, |
609 |
| - allowed_sections=', '.join(ALLOWED_SECTIONS))) |
610 |
| - else: |
611 |
| - if section in unseen_sections: |
612 |
| - section_idx = unseen_sections.index(section) |
613 |
| - unseen_sections = unseen_sections[section_idx + 1:] |
614 |
| - else: |
615 |
| - section_idx = ALLOWED_SECTIONS.index(section) |
616 |
| - goes_before = ALLOWED_SECTIONS[section_idx + 1] |
617 |
| - errs.append(error('GL07', |
618 |
| - sorted_sections=' > '.join(ALLOWED_SECTIONS), |
619 |
| - wrong_section=section, |
620 |
| - goes_before=goes_before)) |
621 |
| - break |
| 604 | + unexpected_sections = [section for section in doc.section_titles |
| 605 | + if section not in ALLOWED_SECTIONS] |
| 606 | + for section in unexpected_sections: |
| 607 | + errs.append(error('GL06', |
| 608 | + section=section, |
| 609 | + allowed_sections=', '.join(ALLOWED_SECTIONS))) |
| 610 | + |
| 611 | + correct_order = [section for section in ALLOWED_SECTIONS |
| 612 | + if section in doc.section_titles] |
| 613 | + if correct_order != doc.section_titles: |
| 614 | + errs.append(error('GL07', |
| 615 | + correct_sections=', '.join(correct_order))) |
622 | 616 |
|
623 | 617 | if not doc.summary:
|
624 | 618 | errs.append(error('SS01'))
|
|
0 commit comments