From ab1356e58c3340d1d0a59ffd6627e5bfeee58b74 Mon Sep 17 00:00:00 2001 From: crasbe Date: Wed, 23 Apr 2025 22:55:54 +0200 Subject: [PATCH] dist/tools: add a leading whitespace check for #pragma once When adding the #pragma once after a comment block, many editors will remain at the previous indentation level, adding a leading whitespace to the #pragma once. This is invalid, but causes the headerguards check to fail. Since it is a common issue, it warrants a separate check with a proposed solution, just like for other headerguard issues that are checked. --- dist/tools/headerguards/headerguards.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dist/tools/headerguards/headerguards.py b/dist/tools/headerguards/headerguards.py index 5683945f72..ec2388482d 100755 --- a/dist/tools/headerguards/headerguards.py +++ b/dist/tools/headerguards/headerguards.py @@ -50,6 +50,10 @@ def fix_headerguard(filename): for line in inlines: if line.startswith("#pragma once"): pragma_once_found += 1 + elif line.lstrip().startswith("#pragma once"): + # check for lines that have leading whitespaces and add a correction + pragma_once_found += 1 + line = "#pragma once\n" if guard_found == 0 and pragma_once_found == 0: if line.startswith("#ifndef"): guard_found += 1