Skip to content

Commit bc63a02

Browse files
committed
Add warnings and set lint issues found to true for bold header that are representing a title
1 parent 14a911b commit bc63a02

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

mlx/robot2rst/style_checker.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,22 @@ def visit_Documentation(self, node):
123123

124124
if self.fix:
125125
# 1. Fix 'smushed' lists
126-
doc_string = re.sub(r'([^\n])\n([ \t]*)([-*+]) ', r'\1\n\n\2\3 ', doc_string)
126+
doc_string, count = re.subn(r'([^\n])\n([ \t]*)([-*+]) ', r'\1\n\n\2\3 ', doc_string)
127+
if count > 0:
128+
LOGGER.warning("%s:%d: Fixed possible 'smushed' lists", self.robot_file, node.lineno)
127129

128130
# 2. Fix 'smushed' bold lines/headers (**text** on its own line will be seen as a header/title).
131+
def fix_bold_header(match):
132+
self.lint_issues_found = True
133+
header_text = match.group(3)
134+
line_number = node.lineno + doc_string[:match.start()].count("\n") + 1
135+
LOGGER.warning("%s:%d: Smushed bold header detected: '%s'. Added blank lines to ensure it is treated "
136+
"as a title.", self.robot_file, line_number, header_text)
137+
138+
return f"{match.group(1)}\n\n{match.group(2)}{header_text}\n\n"
139+
129140
bold_header_pattern = r'([^\n])\n([ \t]*)(\*\*(?:(?!\*\*).)+\*\*)(?:\n|$)'
130-
doc_string = re.sub(bold_header_pattern, r'\1\n\n\2\3\n\n', doc_string)
141+
doc_string = re.sub(bold_header_pattern, fix_bold_header, doc_string)
131142

132143
doc_node = manager.parse_string(doc_string, line_offset=node.lineno-1)
133144
doc_node.settings.tab_width = 4

0 commit comments

Comments
 (0)