Skip to content

Commit

Permalink
fix: don't add spacing between consencutive braces in string [closes s…
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhall88 committed Apr 10, 2024
1 parent 5482660 commit 61b2dbf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions snakefmt/parser/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def operator_skip_spacing(prev_token: Token, token: Token) -> bool:
return True
elif prev_token.type == tokenize.STRING and token.string == ",":
return True
elif prev_token.string == "}" and token.string == "{": # issue #220
return True
else:
return False

Expand Down
9 changes: 6 additions & 3 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,6 @@ def test_f_string_with_double_braces_in_input(self):

def test_f_string_with_double_braces_in_python_code(self):
"""https://github.com/snakemake/snakefmt/issues/215"""
"""def get_test_regions(wildcards):
benchmark = config["variant-calls"][wildcards.callset]["benchmark"]
return f"resources/regions/{benchmark}/test-regions.cov-{{cov}}.bed"""
snakecode = (
"def get_test_regions(wildcards):\n"
f'{TAB * 1}benchmark = config["variant-calls"][wildcards.callset]["benchmark"]\n' # noqa: E501
Expand All @@ -872,6 +869,12 @@ def test_f_string_with_double_braces_in_python_code(self):
formatter = setup_formatter(snakecode)
assert formatter.get_formatted() == snakecode

def test_f_string_spacing_of_consecutive_braces(self):
"""https://github.com/snakemake/snakefmt/issues/222"""
snakecode = 'f"{var1}{var2}"\n'
formatter = setup_formatter(snakecode)
assert formatter.get_formatted() == snakecode


class TestReformatting_SMK_BREAK:
"""
Expand Down

0 comments on commit 61b2dbf

Please sign in to comment.