Skip to content

Commit

Permalink
mformat: fix else token not correctly indented
Browse files Browse the repository at this point in the history
  • Loading branch information
bruchar1 committed Jun 18, 2024
1 parent a3d3efd commit 5b0abf2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mesonbuild/mformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,10 @@ def visit_IfClauseNode(self, node: mparser.IfClauseNode) -> None:
super().visit_IfClauseNode(node)
self.move_whitespaces(node.endif, node)

for if_node in node.ifs:
if_node.whitespaces.value += node.condition_level * self.config.indent_by
if isinstance(node.elseblock, mparser.ElseNode):
node.elseblock.whitespaces.value += node.condition_level * self.config.indent_by
else:
node.ifs[-1].whitespaces.value += node.condition_level * self.config.indent_by

def visit_IfNode(self, node: mparser.IfNode) -> None:
super().visit_IfNode(node)
Expand Down
4 changes: 4 additions & 0 deletions test cases/format/1 default/indentation.meson
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ if meson.project_version().version_compare('>1.2')
],
}
endforeach
elif 42 in d
d += {'foo': 43}
else # ensure else is correctly indented (issue #13316)
k = 'k'
endif
endif

0 comments on commit 5b0abf2

Please sign in to comment.