From patchwork Sun Feb 19 22:17:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Martincoski X-Patchwork-Id: 729666 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vRLqT3SKPz9s7N for ; Mon, 20 Feb 2017 09:22:45 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="L42KAuIQ"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id B690587D19; Sun, 19 Feb 2017 22:22:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 39iT1JJuh4ox; Sun, 19 Feb 2017 22:22:40 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 8A87E876A6; Sun, 19 Feb 2017 22:22:40 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id E094E1C1650 for ; Sun, 19 Feb 2017 22:22:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id DCCAA89853 for ; Sun, 19 Feb 2017 22:22:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FudlyhzLbdSD for ; Sun, 19 Feb 2017 22:22:38 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by hemlock.osuosl.org (Postfix) with ESMTPS id D6D608943C for ; Sun, 19 Feb 2017 22:22:37 +0000 (UTC) Received: by mail-qt0-f196.google.com with SMTP id h53so12031002qth.3 for ; Sun, 19 Feb 2017 14:22:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=QX8XrAzW0PkpKpuum9JglcHBhwzbRd1h9ah1Z1jOfjA=; b=L42KAuIQvk1geVm++D2j+xF70K2OimvyczAJ3sKDyOvgEi98Z3bcrRjiWAjGxq877o JrXbSwkKFk4MuSB4Sk79dnoDRed8S/gxY+/pl1TXCmFnFdlpuf6oaSfhTgI2NXH+OK7H hkKxf2V92gj4PdP+EoD2nzeCEY4W4D/I2OvB3ltIDHvv9gDMedTfBVkgOwLD7EWUYLj/ kamynnNHtQ4mvL+D6hc9jKZa8hgc2JGGZgXVRyzFTTjtHkF4tNXcN7Il991zKGVEHYnt dkMpyjHatJVqXH0OAapMCOIOtF67ny5n17f+iKzIAoHVUGDI9ypl/UeseAtDzB/9eo8X tJTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=QX8XrAzW0PkpKpuum9JglcHBhwzbRd1h9ah1Z1jOfjA=; b=lIgpnRn3RKIBP7F2vnmXNyZ5kaol+jW8y4EUmW/rnF6O7g5cd5r+ozirMqPJF/JaOt i1O1sC8cV/EpxcpqHCfer224YPHMH59mU/8WP5IlFmqSGbitEZctYvubf0WdvYspGW6g tL6GQowK8Dws+qqZMJHWZlkDWY2q1Iu1S0tfXVR4idnmbN6g1MkZU5CWamaV1efnSts9 5PU2PO0vGIzVeKYet9pIflrtgdigaNCjTQiGcQQI82+omW7DTRI4PWWedxcbQgKhKBIS n0WTH17S8rfXziTYi28s17mn1/z8oDy80l9e91uA0XRw8mZ0PBxSH7hTAlLxjcKTIqFD ruEw== X-Gm-Message-State: AMke39lWZ+D+DAnsTAO2RIx4v74fOcYRJNtqMsnArWfgBngsCUX2qycEO0SEymiR7Y15Ww== X-Received: by 10.200.46.162 with SMTP id h31mr16748338qta.164.1487542957040; Sun, 19 Feb 2017 14:22:37 -0800 (PST) Received: from ultri3.home ([201.86.219.185]) by smtp.gmail.com with ESMTPSA id d127sm10970245qka.30.2017.02.19.14.22.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 19 Feb 2017 14:22:36 -0800 (PST) From: Ricardo Martincoski To: buildroot@buildroot.org Date: Sun, 19 Feb 2017 19:17:18 -0300 Message-Id: <20170219221724.27298-4-ricardo.martincoski@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170219221724.27298-1-ricardo.martincoski@gmail.com> References: <20170219221724.27298-1-ricardo.martincoski@gmail.com> In-Reply-To: <20161231032110.11573-1-ricardo.martincoski@gmail.com> References: <20161231032110.11573-1-ricardo.martincoski@gmail.com> Cc: Thomas De Schampheleire , Ricardo Martincoski Subject: [Buildroot] [PATCH v2 3/9] check-package: check whitespace and empty lines X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Create 3 new check functions to warn when: - there are consecutive empty lines in the file, see [1]; - the last line of the file is empty, see [2]; - there are lines with trailing whitespace, see [3]. Apply these functions to Config.*, *.mk and *.hash, but not for *.patch files since they can contain any of these and still be valid. [1] http://patchwork.ozlabs.org/patch/682660/ [2] http://patchwork.ozlabs.org/patch/643288/ [3] http://patchwork.ozlabs.org/patch/398984/ Signed-off-by: Ricardo Martincoski --- Changes v1 -> v2: - update commit subject since now Config.* are tested; - use classes instead of functions to declare each check (Thomas DS); --- Notes: $ time support/scripts/check-package $(find package -type f) >/dev/null 2>/dev/null real 0m0.622s user 0m0.576s sys 0m0.048s ConsecutiveEmptyLines: support/scripts/check-package --include-only ConsecutiveEmptyLines \ $(find package -type f) 2>/dev/null | wc -l 23 (cd support/scripts/check-package-example && \ ../check-package --include-only ConsecutiveEmptyLines -vv package/*/*) package/package1/Config.in:22: consecutive empty lines package/package1/Config.something:3: consecutive empty lines package/package1/package1.hash:8: consecutive empty lines package/package1/package1.mk:25: consecutive empty lines 180 lines processed 4 warnings generated EmptyLastLine: support/scripts/check-package --include-only EmptyLastLine \ $(find package -type f) 2>/dev/null | wc -l 18 (cd support/scripts/check-package-example && \ ../check-package --include-only EmptyLastLine -vv package/*/*) package/package1/package1.hash:8: empty line at end of file package/package1/package1.mk:55: empty line at end of file 180 lines processed 2 warnings generated TrailingSpace: support/scripts/check-package --include-only TrailingSpace \ $(find package -type f) 2>/dev/null | wc -l 5 (cd support/scripts/check-package-example && \ ../check-package --include-only TrailingSpace -vv package/*/*) package/package1/package1.hash:2: line contains trailing whitespace sha256 1234567890123456789012345678901234567890123456789012345678901234 package1-1.0.tar.gz package/package1/package1.hash:7: line contains trailing whitespace package/package1/package1.mk:7: line contains trailing whitespace PACKAGE1_SITE = https://localhost package/package1/package1.mk:14: line contains trailing whitespace PACKAGE1_INSTALL_STAGING=NO package/package1/package1.mk:15: line contains trailing whitespace PACKAGE1_INSTALL_TARGET = YES< tab > package/package1/package1.mk:55: line contains trailing whitespace < tab > 180 lines processed 6 warnings generated support/scripts/checkpackagelib.py | 35 +++++++++++++++++++++++++++++++ support/scripts/checkpackagelib_config.py | 3 +++ support/scripts/checkpackagelib_hash.py | 3 +++ support/scripts/checkpackagelib_mk.py | 3 +++ 4 files changed, 44 insertions(+) diff --git a/support/scripts/checkpackagelib.py b/support/scripts/checkpackagelib.py index 1a4904183..280084575 100644 --- a/support/scripts/checkpackagelib.py +++ b/support/scripts/checkpackagelib.py @@ -3,6 +3,32 @@ from checkpackagebase import _CheckFunction +class ConsecutiveEmptyLines(_CheckFunction): + def before(self): + self.lastline = "non empty" + + def check_line(self, lineno, text): + if text.strip() == "" == self.lastline.strip(): + return ["{}:{}: consecutive empty lines" + .format(self.filename, lineno)] + self.lastline = text + + +class EmptyLastLine(_CheckFunction): + def before(self): + self.lastlineno = 0 + self.lastline = "non empty" + + def check_line(self, lineno, text): + self.lastlineno = lineno + self.lastline = text + + def after(self): + if self.lastline.strip() == "": + return ["{}:{}: empty line at end of file" + .format(self.filename, self.lastlineno)] + + class NewlineAtEof(_CheckFunction): def before(self): self.lastlineno = 0 @@ -17,3 +43,12 @@ class NewlineAtEof(_CheckFunction): return ["{}:{}: missing newline at end of file" .format(self.filename, self.lastlineno), self.lastline] + + +class TrailingSpace(_CheckFunction): + def check_line(self, lineno, text): + line = text.rstrip("\r\n") + if line != line.rstrip(): + return ["{}:{}: line contains trailing whitespace" + .format(self.filename, lineno), + text] diff --git a/support/scripts/checkpackagelib_config.py b/support/scripts/checkpackagelib_config.py index f546d173e..ee5981e64 100644 --- a/support/scripts/checkpackagelib_config.py +++ b/support/scripts/checkpackagelib_config.py @@ -4,4 +4,7 @@ # checked by running "make menuconfig". # Notice: ignore 'imported but unused' from pyflakes for check functions. +from checkpackagelib import ConsecutiveEmptyLines +from checkpackagelib import EmptyLastLine from checkpackagelib import NewlineAtEof +from checkpackagelib import TrailingSpace diff --git a/support/scripts/checkpackagelib_hash.py b/support/scripts/checkpackagelib_hash.py index 8c0337fc9..1f268838f 100644 --- a/support/scripts/checkpackagelib_hash.py +++ b/support/scripts/checkpackagelib_hash.py @@ -4,4 +4,7 @@ # "make package-dirclean package-source". # Notice: ignore 'imported but unused' from pyflakes for check functions. +from checkpackagelib import ConsecutiveEmptyLines +from checkpackagelib import EmptyLastLine from checkpackagelib import NewlineAtEof +from checkpackagelib import TrailingSpace diff --git a/support/scripts/checkpackagelib_mk.py b/support/scripts/checkpackagelib_mk.py index 84eeef889..a37304b6d 100644 --- a/support/scripts/checkpackagelib_mk.py +++ b/support/scripts/checkpackagelib_mk.py @@ -5,4 +5,7 @@ # packages enabled. # Notice: ignore 'imported but unused' from pyflakes for check functions. +from checkpackagelib import ConsecutiveEmptyLines +from checkpackagelib import EmptyLastLine from checkpackagelib import NewlineAtEof +from checkpackagelib import TrailingSpace