mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Formatter: Add trailing commas in lists
This commit is contained in:
parent
55e5095fba
commit
b9f58aeab5
7 changed files with 59 additions and 4 deletions
|
@ -146,8 +146,10 @@ def format(data, tab_size=2, insert_space=True):
|
|||
is_child_type = False
|
||||
|
||||
elif str_item in CLOSING_TOKENS:
|
||||
if str_item == "]" and last_not_whitespace != ",":
|
||||
if str_item == "]" and str(last_not_whitespace) != "[":
|
||||
current_line = current_line[:-1]
|
||||
if str(last_not_whitespace) != ",":
|
||||
current_line += ","
|
||||
commit_current_line()
|
||||
current_line = "]"
|
||||
elif str(last_not_whitespace) in OPENING_TOKENS:
|
||||
|
|
21
tests/formatting/lists_in.blp
Normal file
21
tests/formatting/lists_in.blp
Normal file
|
@ -0,0 +1,21 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Box {
|
||||
styles []
|
||||
}
|
||||
|
||||
Box {
|
||||
styles ["a"]
|
||||
}
|
||||
|
||||
Box {
|
||||
styles ["a",]
|
||||
}
|
||||
|
||||
Box {
|
||||
styles ["a", "b"]
|
||||
}
|
||||
|
||||
Box {
|
||||
styles ["a", "b",]
|
||||
}
|
31
tests/formatting/lists_out.blp
Normal file
31
tests/formatting/lists_out.blp
Normal file
|
@ -0,0 +1,31 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Box {
|
||||
styles []
|
||||
}
|
||||
|
||||
Box {
|
||||
styles [
|
||||
"a",
|
||||
]
|
||||
}
|
||||
|
||||
Box {
|
||||
styles [
|
||||
"a",
|
||||
]
|
||||
}
|
||||
|
||||
Box {
|
||||
styles [
|
||||
"a",
|
||||
"b",
|
||||
]
|
||||
}
|
||||
|
||||
Box {
|
||||
styles [
|
||||
"a",
|
||||
"b",
|
||||
]
|
||||
}
|
|
@ -11,7 +11,7 @@ Overlay {
|
|||
notify::icon-name => $on_icon_name_changed(label) swapped;
|
||||
|
||||
styles [
|
||||
"destructive"
|
||||
"destructive",
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,6 @@ AboutDialog about {
|
|||
|
||||
authors: [
|
||||
"Jane doe <jane-doe@email.com>",
|
||||
"Jhonny D <jd@email.com>"
|
||||
"Jhonny D <jd@email.com>",
|
||||
];
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@ using Gtk 4.0;
|
|||
Label {
|
||||
styles [
|
||||
"class-1",
|
||||
"class-2"
|
||||
"class-2",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -47,3 +47,4 @@ class TestFormatter(unittest.TestCase):
|
|||
self.assert_format_test("correct1.blp", "correct1.blp")
|
||||
self.assert_format_test("string_in.blp", "string_out.blp")
|
||||
self.assert_format_test("comment_in.blp", "comment_out.blp")
|
||||
self.assert_format_test("lists_in.blp", "lists_out.blp")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue