Formatter: Add trailing commas in lists

This commit is contained in:
Alexey Yerin 2025-01-04 10:20:54 +03:00 committed by James Westman
parent 55e5095fba
commit b9f58aeab5
7 changed files with 59 additions and 4 deletions

View file

@ -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:

View 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",]
}

View 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",
]
}

View file

@ -11,7 +11,7 @@ Overlay {
notify::icon-name => $on_icon_name_changed(label) swapped;
styles [
"destructive"
"destructive",
]
}

View file

@ -5,6 +5,6 @@ AboutDialog about {
authors: [
"Jane doe <jane-doe@email.com>",
"Jhonny D <jd@email.com>"
"Jhonny D <jd@email.com>",
];
}

View file

@ -3,6 +3,6 @@ using Gtk 4.0;
Label {
styles [
"class-1",
"class-2"
"class-2",
]
}

View file

@ -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")