Skip to content

Commit

Permalink
fix: collate consecutive directives after if block [#172]
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhall88 committed Feb 2, 2023
1 parent e736235 commit cbe88c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions snakefmt/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def __init__(self, snakefile: TokenIterator):
elif self.from_python:
# We are exiting python context, so force spacing out keywords
self.last_recognised_keyword = ""
self.from_python = self.syntax.from_python
self.flush_buffer(
from_python=self.from_python,
in_global_context=self.in_global_context,
Expand Down
6 changes: 4 additions & 2 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,15 @@ def test_indented_consecutive_snakemake_directives(self):
formatter = setup_formatter(snakecode)
assert formatter.get_formatted() == snakecode

def test_spaced_out_consecutive_dedented_directive(self):
def test_spaced_out_consecutive_dedented_directive_dedented_stays_collated(self):
"""https://github.com/snakemake/snakefmt/pull/172"""
snakecode = (
'if config["load"]:\n\n'
f'{TAB * 1}include: "module_a.smk"\n\n'
f"else:\n\n"
f'{TAB * 1}include: "module_b.smk"\n\n\n'
f'include: "other.smk"\n'
'include: "other.smk"\n'
'include: "other2.smk"\n'
)
formatter = setup_formatter(snakecode)
assert formatter.get_formatted() == snakecode
Expand Down

0 comments on commit cbe88c7

Please sign in to comment.