From bc0b850dfc5b057418fe070e3b97ea29c63ed2bb Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Mon, 17 Oct 2022 15:37:14 +0300 Subject: [PATCH] DescriptionCheck: catch ending with a full stop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: https://bugs.gentoo.org/729968 Signed-off-by: Arthur Zamarin Signed-off-by: Michał Górny --- NEWS.rst | 3 ++ src/pkgcheck/checks/metadata.py | 8 +++-- .../DescriptionCheck/BadDescription/fix.patch | 2 +- .../BadDescription/BadDescription-4.ebuild | 2 +- tests/checks/test_metadata.py | 33 +++++++++++++++---- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index 78c37aa16..c292f92ae 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -14,6 +14,9 @@ pkgcheck 0.10.40 (unreleased) - StabilizationGroupsCheck: check for invalid and non-existant stabilization groups (Arthur Zamarin) +- DescriptionCheck: check for descriptions ending with a full-stop (Arthur + Zamarin and Michał Górny) + **Packaging:** diff --git a/src/pkgcheck/checks/metadata.py b/src/pkgcheck/checks/metadata.py index 0d2fd03c1..6eb528973 100644 --- a/src/pkgcheck/checks/metadata.py +++ b/src/pkgcheck/checks/metadata.py @@ -1515,18 +1515,22 @@ class DescriptionCheck(Check): """DESCRIPTION checks. Check on length (<=80), too short (<10), or generic (lifted from eclass or - just using the package's name). + just using the package's name), or ending with a full stop. """ known_results = frozenset([BadDescription]) def feed(self, pkg): - desc = pkg.description + desc: str = pkg.description s = desc.lower() if s.startswith("based on") and "eclass" in s: yield BadDescription("generic eclass defined description", pkg_desc=desc, pkg=pkg) elif s in (pkg.package.lower(), pkg.key.lower()): yield BadDescription("generic package description", pkg_desc=desc, pkg=pkg) + elif desc.endswith(tuple(".,:;")) and not desc.lower().endswith( + ("etc.", "co.", "inc.", "ltd.", "...") + ): + yield BadDescription("ends with a full stop", pkg_desc=desc, pkg=pkg) else: desc_len = len(desc) if not desc_len: diff --git a/testdata/data/repos/standalone/DescriptionCheck/BadDescription/fix.patch b/testdata/data/repos/standalone/DescriptionCheck/BadDescription/fix.patch index 9500e2b12..85a917c24 100644 --- a/testdata/data/repos/standalone/DescriptionCheck/BadDescription/fix.patch +++ b/testdata/data/repos/standalone/DescriptionCheck/BadDescription/fix.patch @@ -37,7 +37,7 @@ diff -Naur standalone/DescriptionCheck/BadDescription/BadDescription-4.ebuild fi --- standalone/DescriptionCheck/BadDescription/BadDescription-4.ebuild 2019-11-28 00:33:38.457040594 -0700 +++ fixed/DescriptionCheck/BadDescription/BadDescription-4.ebuild 2019-11-28 00:34:59.065514420 -0700 @@ -1,4 +1,4 @@ --DESCRIPTION="Ebuild with DESCRIPTION that is far too long and will be flagged by the BadDescription result since the check triggers at greater than 150 characters long." +-DESCRIPTION="Ebuild with DESCRIPTION that is far too long and will be flagged by the BadDescription result since the check triggers at greater than 150 characters long" +DESCRIPTION="Ebuild with a sane DESCRIPTION" HOMEPAGE="https://github.com/pkgcore/pkgcheck" LICENSE="BSD" diff --git a/testdata/repos/standalone/DescriptionCheck/BadDescription/BadDescription-4.ebuild b/testdata/repos/standalone/DescriptionCheck/BadDescription/BadDescription-4.ebuild index f4d9a2296..8e823634a 100644 --- a/testdata/repos/standalone/DescriptionCheck/BadDescription/BadDescription-4.ebuild +++ b/testdata/repos/standalone/DescriptionCheck/BadDescription/BadDescription-4.ebuild @@ -1,4 +1,4 @@ -DESCRIPTION="Ebuild with DESCRIPTION that is far too long and will be flagged by the BadDescription result since the check triggers at greater than 150 characters long." +DESCRIPTION="Ebuild with DESCRIPTION that is far too long and will be flagged by the BadDescription result since the check triggers at greater than 150 characters long" HOMEPAGE="https://github.com/pkgcore/pkgcheck" LICENSE="BSD" SLOT="0" diff --git a/tests/checks/test_metadata.py b/tests/checks/test_metadata.py index 30b1eceba..a1cd09379 100644 --- a/tests/checks/test_metadata.py +++ b/tests/checks/test_metadata.py @@ -26,13 +26,32 @@ class TestDescriptionCheck(misc.ReportTestCase): def mk_pkg(self, desc=""): return misc.FakePkg("dev-util/diffball-0.7.1", data={"DESCRIPTION": desc}) - def test_good_desc(self): - self.assertNoReport(self.check, self.mk_pkg("a perfectly written package description")) - - def test_bad_descs(self): - for desc in ("based on eclass", "diffball", "dev-util/diffball", "foon"): - r = self.assertReport(self.check, self.mk_pkg(desc)) - assert isinstance(r, metadata.BadDescription) + @pytest.mark.parametrize( + "desc", + ( + "a perfectly written package description", + "foo, bar, etc.", + "something something something...", + ), + ) + def test_good_desc(self, desc: str): + self.assertNoReport(self.check, self.mk_pkg(desc)) + + @pytest.mark.parametrize( + "desc", + ( + "based on eclass", + "diffball", + "dev-util/diffball", + "foon", + "some kind of description.", + "some kind of description,", + "some kind of description..", + ), + ) + def test_bad_descs(self, desc: str): + r = self.assertReport(self.check, self.mk_pkg(desc)) + assert isinstance(r, metadata.BadDescription) def test_desc_length(self): r = self.assertReport(self.check, self.mk_pkg())