Skip to content

Commit 17e5963

Browse files
author
Daniel Kroening
authored
Merge pull request diffblue#1005 from reuk/script-update
Stop attempting to convert previously-converted doc headers
2 parents a2a143a + bec818e commit 17e5963

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

scripts/reformat_docs.py

Lines changed: 10 additions & 3 deletions
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,
@@ -199,9 +204,10 @@ def replace_block(
199204
{f.name: f.contents for f in parse_fields(block_contents.group(1))})
200205

201206
if header_formatter.is_block_valid(block):
202-
return '%s%s\n' % (
203-
block_contents.group(0),
204-
header_formatter.convert(header_from_block(block)))
207+
converted = header_formatter.convert(header_from_block(block))
208+
if header_formatter.needs_new_header(file_contents) and converted:
209+
return block_contents.group(0) + converted + '\n'
210+
return block_contents.group(0)
205211

206212
if class_formatter.is_block_valid(block):
207213
return class_formatter.convert(class_from_block(block))
@@ -231,6 +237,7 @@ def convert_file(file, inplace):
231237
new_contents = block_re.sub(
232238
lambda match: replace_block(
233239
match,
240+
contents,
234241
file,
235242
header_formatter,
236243
class_formatter,

0 commit comments

Comments
 (0)