summaryrefslogtreecommitdiff
path: root/utils/checkstyle.py
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-05-31 14:24:24 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-05-31 20:05:10 +0300
commit5d2c8fa11b921a650584d82d5c98c4b06eee990a (patch)
tree94e8a39e26b95e0f1908ace772745585b210c891 /utils/checkstyle.py
parentb8b24c5b5e02fc6b195ab0acab43f63ddeac8fbc (diff)
utils: checkstyle.py: Extend IncludeChecker to cover math.h
math.h is an exception to the C compatibility header rule, as we prefer using cmath. Extend the IncludeCheck to warn about it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'utils/checkstyle.py')
-rwxr-xr-xutils/checkstyle.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 518be089..f3604299 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -568,7 +568,7 @@ class IncludeChecker(StyleChecker):
headers = ('cassert', 'cctype', 'cerrno', 'cfenv', 'cfloat', 'cinttypes',
'climits', 'clocale', 'csetjmp', 'csignal', 'cstdarg', 'cstddef',
'cstdint', 'cstdio', 'cstdlib', 'cstring', 'ctime', 'cuchar',
- 'cwchar', 'cwctype')
+ 'cwchar', 'cwctype', 'math.h')
include_regex = re.compile(r'^#include <([a-z.]*)>')
def __init__(self, content):
@@ -588,9 +588,15 @@ class IncludeChecker(StyleChecker):
if header not in IncludeChecker.headers:
continue
- header = header[1:] + '.h'
+ if header.endswith('.h'):
+ header_type = 'C++'
+ header = 'c' + header[:-2]
+ else:
+ header_type = 'C compatibility'
+ header = header[1:] + '.h'
+
issues.append(StyleIssue(line_number, line,
- 'C compatibility header <%s> is preferred' % header))
+ f'{header_type} header <{header}> is preferred'))
return issues