diff options
| -rw-r--r-- | mesonbuild/mformat.py | 5 | ||||
| -rw-r--r-- | test cases/format/1 default/indentation.meson | 10 |
2 files changed, 13 insertions, 2 deletions
diff --git a/mesonbuild/mformat.py b/mesonbuild/mformat.py index 184a9d31f..ac36dc08b 100644 --- a/mesonbuild/mformat.py +++ b/mesonbuild/mformat.py @@ -359,6 +359,7 @@ class TrimWhitespaces(FullAstVisitor): super().visit_SymbolNode(node) if node.value in "([{" and node.whitespaces.value == '\n': node.whitespaces.value = '' + node.whitespaces.accept(self) def visit_StringNode(self, node: mparser.StringNode) -> None: self.enter_node(node) @@ -599,8 +600,8 @@ class ArgumentFormatter(FullAstVisitor): if not node.whitespaces.value or node.whitespaces.value == ' ': node.whitespaces.value = '\n' indent_by = (node.condition_level + indent) * self.config.indent_by - if indent_by and node.whitespaces.value.endswith('\n'): - node.whitespaces.value += indent_by + if indent_by: + node.whitespaces.value = re.sub(rf'\n({self.config.indent_by})*', '\n' + indent_by, node.whitespaces.value) def visit_ArrayNode(self, node: mparser.ArrayNode) -> None: self.enter_node(node) diff --git a/test cases/format/1 default/indentation.meson b/test cases/format/1 default/indentation.meson index 7b26e49b1..14e1beb40 100644 --- a/test cases/format/1 default/indentation.meson +++ b/test cases/format/1 default/indentation.meson @@ -110,3 +110,13 @@ if (host_cpu_family == 'x86' and host_system in [ ]) message('hi') endif + +# Underindent in files() (issue #14998) +sources = files( + # bar + # more bar + 'bar.c', + # foo + # more foo + 'foo.c', +) |
