diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-05-31 14:24:24 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-05-31 20:05:25 +0300 |
commit | 4a7c9ce46781a1e6f15c6beb1e6591c7bd69ffb6 (patch) | |
tree | 91c5552116b4a67340049ec339cca4d9a577cb9e /utils | |
parent | 5d2c8fa11b921a650584d82d5c98c4b06eee990a (diff) |
utils: checkstyle.py: Add a check for hex values
libcamera uses lowercase hex values. Add a corresponding checker.
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>
Tested-by: Milan Zamazal <mzamazal@redhat.com>
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/checkstyle.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/utils/checkstyle.py b/utils/checkstyle.py index f3604299..77d6f390 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -562,6 +562,34 @@ class StyleIssue(object): self.msg = msg +class HexValueChecker(StyleChecker): + patterns = ('*.c', '*.cpp', '*.h') + + regex = re.compile(r'\b0[xX][0-9a-fA-F]+\b') + + def __init__(self, content): + super().__init__() + self.__content = content + + def check(self, line_numbers): + issues = [] + + for line_number in line_numbers: + line = self.__content[line_number - 1] + match = HexValueChecker.regex.search(line) + if not match: + continue + + value = match.group(0) + if value == value.lower(): + continue + + issues.append(StyleIssue(line_number, line, + f'Use lowercase hex constant {value.lower()}')) + + return issues + + class IncludeChecker(StyleChecker): patterns = ('*.cpp', '*.h') |