mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-06-21 23:19:24 -04:00
formatter: Also allow /*...*/ as inline comments
Blueprint allows both `//` and `/*...*/` style comments, but if a project prefers only `/*...*/` comments, it is currently not possible to have these inline. Therefore, treat these comments equal if they occur inline. To make this easier to understand, we refactor the comment handling slightly to first handle single-line comment whitespace, and then handle newlines for both single-line and multi-line style comments. Adjust the test accordingly to make sure this works.
This commit is contained in:
parent
5c7fb03da7
commit
ed867269dd
2 changed files with 10 additions and 10 deletions
|
@ -179,17 +179,17 @@ def format(data, tab_size=2, insert_space=True):
|
|||
)
|
||||
|
||||
single_line_comment = str_item.startswith("//")
|
||||
if single_line_comment and not str_item.startswith("// "):
|
||||
current_line = f"// {current_line[2:]}"
|
||||
|
||||
inline_comment = not last_whitespace_contains_newline
|
||||
newlines = 1
|
||||
if single_line_comment:
|
||||
if not str_item.startswith("// "):
|
||||
current_line = f"// {current_line[2:]}"
|
||||
|
||||
if not last_whitespace_contains_newline:
|
||||
current_line = " " + current_line
|
||||
newlines = 0
|
||||
elif prev_line_type == LineType.BLOCK_CLOSE:
|
||||
if inline_comment:
|
||||
current_line = " " + current_line
|
||||
newlines = 0
|
||||
elif single_line_comment:
|
||||
if prev_line_type == LineType.BLOCK_CLOSE:
|
||||
newlines = 2
|
||||
|
||||
elif prev_line_type in require_extra_newline:
|
||||
newlines = 2
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ menu menu {
|
|||
item ("test")
|
||||
|
||||
item {
|
||||
label: "test";
|
||||
label: "test"; /* Different inline comment style */
|
||||
}
|
||||
|
||||
item ("test")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue