From 3fcc1f919251c10c1f1ea105f776d7e9c6f5e18e Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Fri, 22 Sep 2023 12:12:27 +0300 Subject: 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 --- src/pkgcheck/checks/codingstyle.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') 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): -- cgit v1.2.3-65-gdbad