From patchwork Fri Oct 18 19:32:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 21698 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 99033C32AF for ; Fri, 18 Oct 2024 19:33:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1E0DB65394; Fri, 18 Oct 2024 21:33:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="E3geKud4"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6ADBE633C6 for ; Fri, 18 Oct 2024 21:32:55 +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 EFF6C21C; Fri, 18 Oct 2024 21:31:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1729279871; bh=sRWu18G/T97g8sTHlk8+S//JIV1jOROF4ut9yODdjGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E3geKud4WM6LQ4Irkx5/39I0HDjMQ+DT6veRQpgCuyJs396bCrNVmNLMkF79i3nNs LuF/0XnXaoLw2bE0iZoI59J1STg34bt/ldmZcIR5Rf933QlvU9wlNhopJcZsGP5HfH uLSZBPWOZDm6nfLDMfWQlLeEuHkuCws5keOYKvTU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 2/4] utils: checkstyle.py: Turn check() into a class method for all checkers Date: Fri, 18 Oct 2024 22:32:44 +0300 Message-ID: <20241018193246.805-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018193246.805-1-laurent.pinchart@ideasonboard.com> References: <20241018193246.805-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" The check() method of StyleChecker subclasses are instance methods, while CommitChecker subclasses use class methods. This makes unified handling of checkers more complicated. Turn the StyleChecker check() method into a class method, passing it the contents to be checked directly. While at it, fix two style issues reported by checkstyle.py. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- utils/checkstyle.py | 48 +++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 1de518953dcd..bc0ddfad8743 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -598,15 +598,12 @@ class HexValueChecker(StyleChecker): 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): + @classmethod + def check(cls, content, line_numbers): issues = [] for line_number in line_numbers: - line = self.__content[line_number - 1] + line = content[line_number - 1] match = HexValueChecker.regex.search(line) if not match: continue @@ -630,15 +627,12 @@ class IncludeChecker(StyleChecker): 'cwchar', 'cwctype', 'math.h') include_regex = re.compile(r'^#include <([a-z.]*)>') - def __init__(self, content): - super().__init__() - self.__content = content - - def check(self, line_numbers): + @classmethod + def check(self, content, line_numbers): issues = [] for line_number in line_numbers: - line = self.__content[line_number - 1] + line = content[line_number - 1] match = IncludeChecker.include_regex.match(line) if not match: continue @@ -664,14 +658,11 @@ class LogCategoryChecker(StyleChecker): log_regex = re.compile(r'\bLOG\((Debug|Info|Warning|Error|Fatal)\)') patterns = ('*.cpp',) - def __init__(self, content): - super().__init__() - self.__content = content - - def check(self, line_numbers): + @classmethod + def check(cls, content, line_numbers): issues = [] for line_number in line_numbers: - line = self.__content[line_number-1] + line = content[line_number - 1] match = LogCategoryChecker.log_regex.search(line) if not match: continue @@ -685,14 +676,11 @@ class LogCategoryChecker(StyleChecker): class MesonChecker(StyleChecker): patterns = ('meson.build',) - def __init__(self, content): - super().__init__() - self.__content = content - - def check(self, line_numbers): + @classmethod + def check(cls, content, line_numbers): issues = [] for line_number in line_numbers: - line = self.__content[line_number-1] + line = content[line_number - 1] pos = line.find('\t') if pos != -1: issues.append(StyleIssue(line_number, [pos, pos], line, @@ -704,13 +692,10 @@ class ShellChecker(StyleChecker): patterns = ('*.sh',) results_line_regex = re.compile(r'In - line ([0-9]+):') - def __init__(self, content): - super().__init__() - self.__content = content - - def check(self, line_numbers): + @classmethod + def check(cls, content, line_numbers): issues = [] - data = ''.join(self.__content).encode('utf-8') + data = ''.join(content).encode('utf-8') try: ret = subprocess.run(['shellcheck', '-Cnever', '-'], @@ -934,9 +919,8 @@ def check_file(top_level, commit, filename, checkers): # Check for code issues not related to formatting. issues = [] for checker in StyleChecker.instances(filename, checkers): - checker = checker(after) for hunk in commit_diff: - issues += checker.check(hunk.side('to').touched) + issues += checker.check(after, hunk.side('to').touched) # Print the detected issues. if len(issues) == 0 and len(formatted_diff) == 0: