public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: testdata/repos/eclass/InheritsCheck/UnusedInherits/, src/pkgcheck/checks/
@ 2023-01-19 21:19 Arthur Zamarin
  0 siblings, 0 replies; only message in thread
From: Arthur Zamarin @ 2023-01-19 21:19 UTC (permalink / raw
  To: gentoo-commits

commit:     ecaf9a21a58bf441fba8d5e3a5d15f2dc56d1b45
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Thu Jan 19 21:17:37 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Thu Jan 19 21:17:37 2023 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=ecaf9a21

UnusedInherits: fix false positives with indirect usage

Resolves: https://github.com/pkgcore/pkgcheck/issues/355
Resolves: https://github.com/pkgcore/pkgcheck/issues/527
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcheck/checks/codingstyle.py                       | 10 +++++++++-
 .../InheritsCheck/UnusedInherits/UnusedInherits-1.ebuild | 16 ++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py
index 2145e2de..6fec22ca 100644
--- a/src/pkgcheck/checks/codingstyle.py
+++ b/src/pkgcheck/checks/codingstyle.py
@@ -796,6 +796,8 @@ class InheritsCheck(Check):
             if eclass := self.get_eclass(name, pkg):
                 assigned_vars[name] = eclass
 
+        # eclasses which might be used indirectly, so we won't trigger UnusedInherits
+        weak_used_eclasses = set()
         # match captured commands with eclasses
         used = defaultdict(list)
         for node, _ in bash.cmd_query.captures(pkg.tree.root_node):
@@ -806,6 +808,7 @@ class InheritsCheck(Check):
                 eclasses = call.split()[1:]
                 if not pkg.inherited.intersection(eclasses):
                     conditional.update(eclasses)
+                continue
             # 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() | defined_funcs:
@@ -813,6 +816,11 @@ class InheritsCheck(Check):
                 if eclass := self.get_eclass(name, pkg):
                     used[eclass].append((lineno + 1, name, call.split("\n", 1)[0]))
 
+            for arg in node.children[1:]:
+                arg_name = pkg.node_str(arg).strip("'\"")
+                if eclass := self.get_eclass(arg_name, pkg):
+                    weak_used_eclasses.add(eclass)
+
         # match captured variables with eclasses
         for node, _ in bash.var_query.captures(pkg.tree.root_node):
             name = pkg.node_str(node)
@@ -828,7 +836,7 @@ class InheritsCheck(Check):
         # missing inherits
         missing = used.keys() - pkg.inherit - indirect_allowed - conditional
 
-        unused = set(pkg.inherit) - used.keys() - set(assigned_vars.values())
+        unused = set(pkg.inherit) - used.keys() - set(assigned_vars.values()) - weak_used_eclasses
         # remove eclasses that use implicit phase functions
         if unused and pkg.defined_phases:
             phases = [pkg.eapi.phases[x] for x in pkg.defined_phases]

diff --git a/testdata/repos/eclass/InheritsCheck/UnusedInherits/UnusedInherits-1.ebuild b/testdata/repos/eclass/InheritsCheck/UnusedInherits/UnusedInherits-1.ebuild
new file mode 100644
index 00000000..d3aaef8a
--- /dev/null
+++ b/testdata/repos/eclass/InheritsCheck/UnusedInherits/UnusedInherits-1.ebuild
@@ -0,0 +1,16 @@
+EAPI=7
+
+inherit inherit unused
+
+DESCRIPTION="Ebuild using inherited function indirectly"
+HOMEPAGE="https://github.com/pkgcore/pkgcheck"
+SLOT="0"
+LICENSE="BSD"
+
+src_prepare() {
+	inherit_public_func
+}
+
+src_test() {
+	edo unused_function
+}


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-19 21:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-19 21:19 [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: testdata/repos/eclass/InheritsCheck/UnusedInherits/, src/pkgcheck/checks/ Arthur Zamarin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox