From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id A2F9615ACFB for ; Mon, 24 Apr 2023 16:43:03 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D7008E0839; Mon, 24 Apr 2023 16:43:02 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A832DE0839 for ; Mon, 24 Apr 2023 16:43:02 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B655A33BEEA for ; Mon, 24 Apr 2023 16:43:01 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 13D10909 for ; Mon, 24 Apr 2023 16:43:00 +0000 (UTC) From: "Arthur Zamarin" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arthur Zamarin" Message-ID: <1682354360.fdcf83d0811019e0a465006493fe4acad77043da.arthurzam@gentoo> Subject: [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: src/pkgcheck/checks/, ... X-VCS-Repository: proj/pkgcore/pkgcheck X-VCS-Files: src/pkgcheck/checks/whitespace.py testdata/data/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/expected.json testdata/data/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/fix.patch testdata/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/MissingEAPIBlankLine-0.ebuild tests/checks/test_whitespace.py X-VCS-Directories: tests/checks/ testdata/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/ testdata/data/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/ src/pkgcheck/checks/ X-VCS-Committer: arthurzam X-VCS-Committer-Name: Arthur Zamarin X-VCS-Revision: fdcf83d0811019e0a465006493fe4acad77043da X-VCS-Branch: master Date: Mon, 24 Apr 2023 16:43:00 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 09710f3f-44fd-4b7c-879f-47efe2d9a38d X-Archives-Hash: 0b76bcac5c7383835087733a3a8933f5 commit: fdcf83d0811019e0a465006493fe4acad77043da Author: Arthur Zamarin gentoo org> AuthorDate: Mon Apr 24 16:39:20 2023 +0000 Commit: Arthur Zamarin gentoo org> CommitDate: Mon Apr 24 16:39:20 2023 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=fdcf83d0 MissingEAPIBlankLine: make it optional Requested by multiple devs, maybe in future we would improve logic, and un-optional it. Signed-off-by: Arthur Zamarin gentoo.org> src/pkgcheck/checks/whitespace.py | 29 ++++++++++++++++------ .../MissingEAPIBlankLine/expected.json | 1 - .../WhitespaceCheck/MissingEAPIBlankLine/fix.patch | 9 ------- .../MissingEAPIBlankLine-0.ebuild | 5 ---- tests/checks/test_whitespace.py | 18 ++++++++++++++ 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/pkgcheck/checks/whitespace.py b/src/pkgcheck/checks/whitespace.py index 31667f9c..a853e0b0 100644 --- a/src/pkgcheck/checks/whitespace.py +++ b/src/pkgcheck/checks/whitespace.py @@ -4,7 +4,7 @@ import re from typing import NamedTuple from .. import results, sources -from . import Check +from . import Check, OptionalCheck class _Whitespace(results.LinesResult, results.Style): @@ -131,7 +131,6 @@ class WhitespaceCheck(Check): TrailingEmptyLine, NoFinalNewline, BadWhitespaceCharacter, - MissingEAPIBlankLine, } ) @@ -148,14 +147,8 @@ class WhitespaceCheck(Check): leading = [] indent = [] double_empty = [] - eapi_lineno = None for lineno, line in enumerate(pkg.lines, 1): - if line.startswith("EAPI="): - eapi_lineno = lineno - elif eapi_lineno is not None and lineno == eapi_lineno + 1 and line != "\n": - yield MissingEAPIBlankLine(pkg=pkg) - for match in self.bad_whitespace_regex.finditer(line): yield BadWhitespaceCharacter( repr(match.group("char")), @@ -191,3 +184,23 @@ class WhitespaceCheck(Check): # Dealing with empty ebuilds is just paranoia if pkg.lines and not pkg.lines[-1].endswith("\n"): yield NoFinalNewline(pkg=pkg) + + +class MissingWhitespaceCheck(OptionalCheck): + """Scan ebuild for missing whitespace.""" + + _source = sources.EbuildFileRepoSource + known_results = frozenset( + { + MissingEAPIBlankLine, + } + ) + + def feed(self, pkg): + eapi_lineno = None + + for lineno, line in enumerate(pkg.lines, 1): + if line.startswith("EAPI="): + eapi_lineno = lineno + elif eapi_lineno is not None and lineno == eapi_lineno + 1 and line != "\n": + yield MissingEAPIBlankLine(pkg=pkg) diff --git a/testdata/data/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/expected.json b/testdata/data/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/expected.json deleted file mode 100644 index d0630087..00000000 --- a/testdata/data/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/expected.json +++ /dev/null @@ -1 +0,0 @@ -{"__class__": "MissingEAPIBlankLine", "category": "WhitespaceCheck", "package": "MissingEAPIBlankLine", "version": "0"} diff --git a/testdata/data/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/fix.patch b/testdata/data/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/fix.patch deleted file mode 100644 index e6b838e3..00000000 --- a/testdata/data/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/fix.patch +++ /dev/null @@ -1,9 +0,0 @@ -diff -Naur standalone/WhitespaceCheck/MissingEAPIBlankLine/MissingEAPIBlankLine-0.ebuild fixed/WhitespaceCheck/MissingEAPIBlankLine/MissingEAPIBlankLine-0.ebuild ---- standalone/WhitespaceCheck/MissingEAPIBlankLine/MissingEAPIBlankLine-0.ebuild -+++ fixed/WhitespaceCheck/MissingEAPIBlankLine/MissingEAPIBlankLine-0.ebuild -@@ -1,4 +1,5 @@ - EAPI=7 -+ - DESCRIPTION="Ebuild is missing blank line after EAPI" - HOMEPAGE="https://github.com/pkgcore/pkgcheck" - SLOT="0" diff --git a/testdata/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/MissingEAPIBlankLine-0.ebuild b/testdata/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/MissingEAPIBlankLine-0.ebuild deleted file mode 100644 index fc5a6781..00000000 --- a/testdata/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/MissingEAPIBlankLine-0.ebuild +++ /dev/null @@ -1,5 +0,0 @@ -EAPI=7 -DESCRIPTION="Ebuild is missing blank line after EAPI" -HOMEPAGE="https://github.com/pkgcore/pkgcheck" -SLOT="0" -LICENSE="BSD" diff --git a/tests/checks/test_whitespace.py b/tests/checks/test_whitespace.py index f90495b6..e6324d77 100644 --- a/tests/checks/test_whitespace.py +++ b/tests/checks/test_whitespace.py @@ -150,3 +150,21 @@ class TestMultipleChecks(WhitespaceCheckTest): reports = self.assertReports(self.check, fake_pkg) assert len(reports) == 4 + + +class TestMissingWhitespaceCheck(misc.ReportTestCase): + check_kls = whitespace.MissingWhitespaceCheck + check = whitespace.MissingWhitespaceCheck(None) + + def test_it(self): + fake_src = [ + "# This is a comment\n", + "# This is a comment\n", + "# This is a comment, and no blank line before EAPI\n", + "EAPI=8\n", + "inherit fake\n", # no blank line after EAPI= + ] + fake_pkg = misc.FakePkg("dev-util/diffball-0.5", lines=fake_src) + + r = self.assertReport(self.check, fake_pkg) + assert isinstance(r, whitespace.MissingEAPIBlankLine)