Skip to content

Commit

Permalink
fix: raise error on empty named param (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhall88 committed Mar 8, 2023
1 parent fd5680a commit b5aa660
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions snakefmt/parser/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ def process_token(self, cur_param: Parameter, prev_token: Token) -> Parameter:
return cur_param

def flush_param(self, parameter: Parameter, skip_empty: bool = False) -> None:
if parameter.has_a_key() and not parameter.has_value():
raise NoParametersError(
f"{self.line_nb}In {self.keyword_name} definition, "
f"keyword {parameter.key}"
)

if not parameter.has_value() and skip_empty:
return

Expand Down
11 changes: 11 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ def test_dictionary_unpacking_passes(self):
)
setup_formatter(snake_code)

def test_key_value_no_value_fails(self):
"""https://github.com/snakemake/snakefmt/issues/125"""
snakecode = (
"rule foo:\n"
f"{TAB * 1}input:\n"
f'{TAB * 2}bar="file.txt",\n'
f"{TAB * 2}baz=\n"
)
with pytest.raises(NoParametersError, match="baz"):
setup_formatter(snakecode)


class TestIndentationErrors:
def test_param_collating(self):
Expand Down

0 comments on commit b5aa660

Please sign in to comment.