commit: d2a5afc73f39786877d7a3353be94f4cbcb5a2a2 Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> AuthorDate: Mon Jan 9 18:25:52 2023 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Mon Jan 9 18:25:52 2023 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=d2a5afc7
MissingInherits: don't show for functions defined in ebuild Resolves: https://github.com/pkgcore/pkgcheck/issues/513 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/pkgcheck/checks/codingstyle.py | 10 ++++++++-- .../MissingInherits/MissingInherits-2.ebuild | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py index 6d3e53ca..ea315259 100644 --- a/src/pkgcheck/checks/codingstyle.py +++ b/src/pkgcheck/checks/codingstyle.py @@ -783,6 +783,12 @@ class InheritsCheck(Check): def feed(self, pkg): conditional = set() + # collect globally defined functions in ebuild + defined_funcs = { + pkg.node_str(func_node.child_by_field_name("name")) + for func_node, _ in bash.func_query.captures(pkg.tree.root_node) + } + # register variables assigned in ebuilds assigned_vars = dict() for node, _ in bash.var_assign_query.captures(pkg.tree.root_node): @@ -802,8 +808,8 @@ class InheritsCheck(Check): conditional.update(eclasses) # Also ignore vars since any used in arithmetic expansions, i.e. # $((...)), are captured as commands. - elif name not in self.eapi_funcs[pkg.eapi] | assigned_vars.keys(): - lineno, colno = node.start_point + elif name not in self.eapi_funcs[pkg.eapi] | assigned_vars.keys() | defined_funcs: + lineno, _colno = node.start_point if eclass := self.get_eclass(name, pkg): used[eclass].append((lineno + 1, name, call.split("\n", 1)[0])) diff --git a/testdata/repos/eclass/InheritsCheck/MissingInherits/MissingInherits-2.ebuild b/testdata/repos/eclass/InheritsCheck/MissingInherits/MissingInherits-2.ebuild new file mode 100644 index 00000000..9aa0432e --- /dev/null +++ b/testdata/repos/eclass/InheritsCheck/MissingInherits/MissingInherits-2.ebuild @@ -0,0 +1,15 @@ +EAPI=7 + +DESCRIPTION="Ebuild missing an eclass inherit" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +SLOT="0" +LICENSE="BSD" + +src_prepare() { + inherit_public_func + unset EBUILD_TEST +} + +inherit_public_func() { + echo "inherit_public_func" +}