diff --git a/cmakelang/format/formatter.py b/cmakelang/format/formatter.py index 06a345b..460f8c6 100644 --- a/cmakelang/format/formatter.py +++ b/cmakelang/format/formatter.py @@ -99,7 +99,7 @@ def format_comment_lines(node, stack_context, line_width): items = markup.parse(inlines, config) markup_lines = markup.format_items(config, max(10, line_width - 2), items) - return [prefix + (" " * len(line[:1])) + line for line in markup_lines] + return [prefix + (" " * len(line[:1]) if not line.startswith(prefix) else "") + line for line in markup_lines] def normalize_line_endings(instr): diff --git a/cmakelang/format/testdata/test_in.cmake b/cmakelang/format/testdata/test_in.cmake index 7db69b7..a29a172 100644 --- a/cmakelang/format/testdata/test_in.cmake +++ b/cmakelang/format/testdata/test_in.cmake @@ -10,6 +10,10 @@ project(cmakelang_test) # into a single comment # on one line +###################### +# This is some section +###################### + # This comment should remain right before the command call. # Furthermore, the command call should be formatted # to a single line. diff --git a/cmakelang/format/testdata/test_out.cmake b/cmakelang/format/testdata/test_out.cmake index 360b720..bc8ca17 100644 --- a/cmakelang/format/testdata/test_out.cmake +++ b/cmakelang/format/testdata/test_out.cmake @@ -5,6 +5,10 @@ project(cmakelang_test) # This multiline-comment should be reflowed into a single comment on one line +############################################################################### +# This is some section +############################################################################### + # This comment should remain right before the command call. Furthermore, the # command call should be formatted to a single line. add_subdirectories(foo bar baz foo2 bar2 baz2)