dist/tools/headerguards: use regex to check include guard name - #22537
Merged
Conversation
Enoch247
approved these changes
Aug 1, 2026
Enoch247
left a comment
Contributor
There was a problem hiding this comment.
I trust the test cases you already checked, and did not re-run them. I did run a few of my own though:
This should pass, and does:
josh@dragonkite:fix_headerguard_check$ git diff
diff --git a/drivers/abp2/include/abp2_params.h b/drivers/abp2/include/abp2_params.h
index b5def22f3b..652eed3fd4 100644
--- a/drivers/abp2/include/abp2_params.h
+++ b/drivers/abp2/include/abp2_params.h
@@ -3,7 +3,8 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
-#pragma once
+#ifndef ABP2_PARAMS_H
+#define ABP2_PARAMS_H
/**
* @ingroup drivers_abp2
@@ -112,3 +113,5 @@ static const saul_reg_info_t abp2_saul_info[][2] =
#endif
/** @} */
+
+#endif /* ABP2_PARAMS_H */
josh@dragonkite:fix_headerguard_check$ ./dist/tools/headerguards/check.sh
josh@dragonkite:fix_headerguard_check$This should fail, and does:
josh@dragonkite:fix_headerguard_check$ git diff
diff --git a/drivers/abp2/include/abp2_params.h b/drivers/abp2/include/abp2_params.h
index b5def22f3b..252b86809d 100644
--- a/drivers/abp2/include/abp2_params.h
+++ b/drivers/abp2/include/abp2_params.h
@@ -5,6 +5,9 @@
#pragma once
+#ifndef ABP2_PARAMS_H
+#define ABP2_PARAMS_H
+
/**
* @ingroup drivers_abp2
* @{
@@ -112,3 +115,5 @@ static const saul_reg_info_t abp2_saul_info[][2] =
#endif
/** @} */
+
+#endif /* ABP2_PARAMS_H */
josh@dragonkite:fix_headerguard_check$ ./dist/tools/headerguards/check.sh
drivers/abp2/include/abp2_params.h: #pragma once and classic header guards used in the same file
Contributor
|
I should learn to read more carefully. You already provided tests for regression. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
The headerguard check tried to find if classic header guards were used by matching the beginning of the line with
#ifndef $(filename_with_underscores). So fordrivers/abp2/include/abp2_params.hit would try to find#ifndef ABP2_PARAMS_H*.The issue arises when you have a parameter that has a word starting with H, for example
#ifndef ABP2_PARAMS_HWTIMER, creating a false positive.Instead of matching the line start, I changed it to a RegEx to match either
#ifndef ABP2_PARAMS_Hor#ifndef ABP2_PARAMS_H_, but nothing else.Testing procedure
Test for Bug Fixed
Add
#ifndef ABP2_PARAMS_HWTIMERtodrivers/abp2/include/abp2_params.hand it should not still complain.Behavior on
master, it complains:Behavior with this PR, it does not complain:
Test for Regression
#ifndef ABP2_PARAMS_Htodrivers/abp2/include/abp2_params.hand it should still complain:#ifndef ABP2_PARAMS_H_todrivers/abp2/include/abp2_params.hand it should still complain:Issues/PRs references
Found in #19848.
Declaration of AI-Tools / LLMs usage:
AI-Tools / LLMs that were used are: