summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniël van de Giessen <daniel@dvdgiessen.nl>2025-08-05 13:21:59 +0200
committerDamien George <damien@micropython.org>2025-08-11 13:35:34 +1000
commit485dac783b8ba7b88fdbf28fcdf54eb053cd8ef7 (patch)
tree9a014ce8e76272b0c27efc60a4998f87b1114df9
parent6e450dba7e5042355462b807400ba8d389fc17e5 (diff)
tools/codeformat.py: Print filename + linenumber when dedenting fails.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
-rwxr-xr-xtools/codeformat.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/codeformat.py b/tools/codeformat.py
index afba5c336..7f13a059f 100755
--- a/tools/codeformat.py
+++ b/tools/codeformat.py
@@ -75,6 +75,10 @@ TOP = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
UNCRUSTIFY_CFG = os.path.join(TOP, "tools/uncrustify.cfg")
+class IndentationError(ValueError):
+ pass
+
+
def list_files(paths, exclusions=None, prefix=""):
files = set()
for pattern in paths:
@@ -111,6 +115,10 @@ def fixup_c(filename):
# This #-line does not need dedenting.
dedent_stack.append(-1)
else:
+ if len(dedent_stack) == 0:
+ raise IndentationError(
+ f'dedent stack is empty for "{directive}" at {filename}:{line_number}'
+ )
if dedent_stack[-1] >= 0:
# This associated #-line needs dedenting to match the #if.
indent_diff = indent - dedent_stack[-1]