* [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: testdata/repos/standalone/BadCommandsCheck/BannedPhaseCall/, ...
@ 2023-09-23 15:35 Arthur Zamarin
0 siblings, 0 replies; only message in thread
From: Arthur Zamarin @ 2023-09-23 15:35 UTC (permalink / raw
To: gentoo-commits
commit: 3fcc1f919251c10c1f1ea105f776d7e9c6f5e18e
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Fri Sep 22 09:12:27 2023 +0000
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sat Sep 23 15:12:43 2023 +0000
URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=3fcc1f91
BannedPhaseCall: detect calls of phase functions directly
Resolves: https://github.com/pkgcore/pkgcheck/issues/625
Closes: https://bugs.gentoo.org/596616
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
src/pkgcheck/checks/codingstyle.py | 12 +++++++++++-
.../BadCommandsCheck/BannedPhaseCall/expected.json | 1 +
.../BannedPhaseCall/BannedPhaseCall-0.ebuild | 14 ++++++++++++++
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py
index ad75436b..1838be28 100644
--- a/src/pkgcheck/checks/codingstyle.py
+++ b/src/pkgcheck/checks/codingstyle.py
@@ -61,11 +61,19 @@ class BannedEapiCommand(_EapiCommandResult, results.Error):
_status = "banned"
+class BannedPhaseCall(results.Error, results.LineResult):
+ """Ebuild calls a phase function directly."""
+
+ @property
+ def desc(self):
+ return f"line {self.lineno}: calling phase function {self.line!r} directly is invalid"
+
+
class BadCommandsCheck(Check):
"""Scan ebuild for various deprecated and banned command usage."""
_source = sources.EbuildParseRepoSource
- known_results = frozenset([DeprecatedEapiCommand, BannedEapiCommand])
+ known_results = frozenset({DeprecatedEapiCommand, BannedEapiCommand, BannedPhaseCall})
def feed(self, pkg):
for func_node, _ in bash.func_query.captures(pkg.tree.root_node):
@@ -81,6 +89,8 @@ class BadCommandsCheck(Check):
yield DeprecatedEapiCommand(
name, line=call, lineno=lineno + 1, eapi=pkg.eapi, pkg=pkg
)
+ elif name in pkg.eapi.phases.values():
+ yield BannedPhaseCall(line=name, lineno=lineno + 1, pkg=pkg)
class EendMissingArg(results.LineResult, results.Warning):
diff --git a/testdata/data/repos/standalone/BadCommandsCheck/BannedPhaseCall/expected.json b/testdata/data/repos/standalone/BadCommandsCheck/BannedPhaseCall/expected.json
new file mode 100644
index 00000000..cf55baad
--- /dev/null
+++ b/testdata/data/repos/standalone/BadCommandsCheck/BannedPhaseCall/expected.json
@@ -0,0 +1 @@
+{"__class__": "BannedPhaseCall", "category": "BadCommandsCheck", "package": "BannedPhaseCall", "version": "0", "line": "pkg_postinst", "lineno": 13}
diff --git a/testdata/repos/standalone/BadCommandsCheck/BannedPhaseCall/BannedPhaseCall-0.ebuild b/testdata/repos/standalone/BadCommandsCheck/BannedPhaseCall/BannedPhaseCall-0.ebuild
new file mode 100644
index 00000000..c7177c07
--- /dev/null
+++ b/testdata/repos/standalone/BadCommandsCheck/BannedPhaseCall/BannedPhaseCall-0.ebuild
@@ -0,0 +1,14 @@
+EAPI=8
+
+DESCRIPTION="Ebuild calls phase function directly"
+HOMEPAGE="https://github.com/pkgcore/pkgcheck"
+SLOT="0"
+LICENSE="BSD"
+
+pkg_postinst() {
+ echo "something"
+}
+
+pkg_postrm() {
+ pkg_postinst
+}
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-09-23 15:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-23 15:35 [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: testdata/repos/standalone/BadCommandsCheck/BannedPhaseCall/, Arthur Zamarin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox