Formatter: adapt to unittest

This commit is contained in:
gregorni 2023-09-08 09:56:52 +02:00
parent 13b66e2875
commit 825f6e3b15
2 changed files with 21 additions and 6 deletions

View file

@ -26,11 +26,17 @@ CLOSING_TOKENS = ["}", "]"]
NEWLINE_AFTER = [";"] + OPENING_TOKENS + CLOSING_TOKENS NEWLINE_AFTER = [";"] + OPENING_TOKENS + CLOSING_TOKENS
NO_WHITESPACE_BEFORE = [",", ":", ";", ")", "."] NO_WHITESPACE_BEFORE = [",", ":", "::", ";", ")", ".", ">"]
NO_WHITESPACE_AFTER = ["C_", "_", "("] NO_WHITESPACE_AFTER = ["C_", "_", "("]
WHITESPACE_AFTER = [":", ","] # NO_WHITESPACE_BEFORE takes precedence over WHITESPACE_AFTER
WHITESPACE_BEFORE = ["{"] WHITESPACE_AFTER = [
":",
",",
">",
")",
]
WHITESPACE_BEFORE = ["{", "$"]
class LineType(Enum): class LineType(Enum):
@ -77,7 +83,11 @@ class Format:
if item.type != tokenizer.TokenType.WHITESPACE: if item.type != tokenizer.TokenType.WHITESPACE:
str_item = str(item) str_item = str(item)
if item.type == tokenizer.TokenType.QUOTED and str_item.startswith('"'): if item.type == tokenizer.TokenType.QUOTED and str_item.startswith('"'):
str_item = ("'" + str_item[1:-1] + "'").replace('\\"', '"') str_item = (
"'"
+ str_item[1:-1].replace('\\"', '"').replace("'", "\\'")
+ "'"
)
if ( if (
str_item in WHITESPACE_BEFORE str_item in WHITESPACE_BEFORE
@ -117,7 +127,10 @@ class Format:
indent_levels += 1 indent_levels += 1
commit_current_line( commit_current_line(
1 if prev_line_type == LineType.CHILD_TYPE else 2, 1
if prev_line_type == LineType.CHILD_TYPE
or tokenized_str.strip()[-1] == "{"
else 2,
LineType.BLOCK_OPEN, LineType.BLOCK_OPEN,
) )

View file

@ -10,7 +10,9 @@ Overlay {
Button { Button {
notify::icon-name => $on_icon_name_changed (label) swapped; notify::icon-name => $on_icon_name_changed (label) swapped;
styles ['destructive'] styles [
'destructive'
]
} }
visible: bind $isVisible (label.visible, my-menu) as <bool>; visible: bind $isVisible (label.visible, my-menu) as <bool>;