From patchwork Mon Mar 16 13:21:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 3116 Return-Path: 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 8EBAA6041A for ; Mon, 16 Mar 2020 14:21:25 +0100 (CET) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0BC7DA3B; Mon, 16 Mar 2020 14:21:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584364885; bh=OdJO/IwUjNpnKpDiAAqvdTgWSD4UykLOtGk3HWIMw7U=; h=From:To:Cc:Subject:Date:From; b=gv2HTUC05r0rCu+Jq6h34fqVTumGADBiCDxXVn+TkIdvZ14pnDG9har5XWZ4sFEid 1Iju/NH9JsUimBmYsUP+FC9mSgNDsXyZrXMi4wg8iN5EBLO0LoGR0lhmElNPCnPOug DMPWZbwb1jUNjX4Rawpm4v1vcrBHFmd0czWVWdq4= From: Kieran Bingham To: libcamera devel Date: Mon, 16 Mar 2020 13:21:21 +0000 Message-Id: <20200316132121.23330-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] utils: checkstyle: Add a ShellChecker 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: , X-List-Received-Date: Mon, 16 Mar 2020 13:21:25 -0000 Hook the utility 'shellcheck' into our checkstyle helper to automatically verify shell script additions. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- utils/checkstyle.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 5ac14508bad5..0827a1e6ba0f 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -341,6 +341,44 @@ class Pep8Checker(StyleChecker): return issues +class ShellChecker(StyleChecker): + patterns = ('*.sh',) + results_line_regex = re.compile('In - line ([0-9]+):') + + def __init__(self, content): + super().__init__() + self.__content = content + + def check(self, line_numbers): + issues = [] + data = ''.join(self.__content).encode('utf-8') + + try: + ret = subprocess.run(['shellcheck', '-Cnever', '-'], + input=data, stdout=subprocess.PIPE) + except FileNotFoundError: + issues.append(StyleIssue(0, None, "Please install shellcheck to validate shell script additions")) + return issues + + results = ret.stdout.decode('utf-8').splitlines() + for nr, item in enumerate(results): + search = re.search(ShellChecker.results_line_regex, item) + if search is None: + continue + + line_number = int(search.group(1)) + line = results[nr + 1] + msg = results[nr + 2] + + # Determined, but not yet used + position = msg.find('^') + 1 + + if line_number in line_numbers: + issues.append(StyleIssue(line_number, line, msg)) + + return issues + + # ------------------------------------------------------------------------------ # Formatters #