From patchwork Fri May 31 12:18:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20168 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 16293BDE6B for ; Fri, 31 May 2024 12:19:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 26665634BB; Fri, 31 May 2024 14:19:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nJmGtGAJ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 71458634B6 for ; Fri, 31 May 2024 14:18:56 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 78A3611A3 for ; Fri, 31 May 2024 14:18:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1717157931; bh=/grH61Oa58Xd/XOJhnfvS+wRUgiDdZb2p+iyyZJZDyU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nJmGtGAJrqQV7VczXjdwbKnsrPhhc6eDBuUAbfmQZ9Z9paiQ3rW6218AFwnusCCid ykOa/2KWbJ/X6gxWLXwqEl3YLZd448OBoD3kX8a29a+FywpyFCptFpJo/svZza3V/u Is603j9kBowGp0qv7CyxDnVACQbsXO5Z8QsVV/fM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 3/4] utils: checkstyle.py: Add a check for hex values Date: Fri, 31 May 2024 15:18:37 +0300 Message-ID: <20240531121838.27643-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240531121838.27643-1-laurent.pinchart@ideasonboard.com> References: <20240531121838.27643-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" libcamera uses lowercase hex values. Add a corresponding checker. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- utils/checkstyle.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index f3604299de94..77d6f39011c1 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')