Skip to content

Commit fb6ae81

Browse files
committed
Apply fix from #1005
1 parent f305de6 commit fb6ae81

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

scripts/reformat_docs.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def is_block_valid(self, block):
9595
def convert_sections(self, block):
9696
return [self.format_module(block)]
9797

98+
def needs_new_header(self, file_contents):
99+
return (re.search(r'^\/\/\/ \\file$', file_contents, flags=re.MULTILINE)
100+
is None)
101+
98102

99103
class FunctionFormatter(GenericFormatter):
100104
def __init__(self, doc_width):
@@ -188,6 +192,7 @@ def convert_sections(self, block):
188192

189193
def replace_block(
190194
block_contents,
195+
file_contents,
191196
file,
192197
header_formatter,
193198
class_formatter,
@@ -200,7 +205,7 @@ def replace_block(
200205

201206
if header_formatter.is_block_valid(block):
202207
converted = header_formatter.convert(header_from_block(block))
203-
if converted:
208+
if header_formatter.needs_new_header(file_contents) and converted:
204209
return '%s%s' % (
205210
block_contents.group(0),
206211
header_formatter.convert(header_from_block(block)) + '\n')
@@ -234,6 +239,7 @@ def convert_file(file, inplace):
234239
new_contents = block_re.sub(
235240
lambda match: replace_block(
236241
match,
242+
contents,
237243
file,
238244
header_formatter,
239245
class_formatter,

0 commit comments

Comments
 (0)