aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Ryan <anthonyryan1@gmail.com>2024-01-06 02:16:15 -0500
committerArthur Zamarin <arthurzam@gentoo.org>2024-01-28 07:04:49 +0200
commit7498b68f4b40cebb55f0db98085718cc60374771 (patch)
tree773e8f2a84ee024859d7d5aaeaf9892f0f07968e /src/pkgcheck
parentdocs: Add intersphinx linkages (diff)
downloadpkgcheck-7498b68f4b40cebb55f0db98085718cc60374771.tar.gz
pkgcheck-7498b68f4b40cebb55f0db98085718cc60374771.tar.bz2
pkgcheck-7498b68f4b40cebb55f0db98085718cc60374771.zip
VariableOrderWrong: Enforce skel.ebuild variable order
Gentoo developers are rejecting routine version bumps for ebuild variables being defined in a different order than skel.ebuild. This new lint ensures pkgcheck identifies these problems before we waste developer time. Regarding tests, in spite of the massive diff, all that's been done is re-ordering the variables to avoid introducing new style warnings into existing tests. Signed-off-by: Anthony Ryan <anthonyryan1@gmail.com> Closes: https://github.com/pkgcore/pkgcheck/pull/645 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'src/pkgcheck')
-rw-r--r--src/pkgcheck/checks/codingstyle.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py
index 67dbe6c1..63704e47 100644
--- a/src/pkgcheck/checks/codingstyle.py
+++ b/src/pkgcheck/checks/codingstyle.py
@@ -1572,3 +1572,53 @@ class SandboxCallCheck(Check):
if len(args) != 1 or ":" in pkg.node_str(args[0]):
lineno, _ = node.start_point
yield InvalidSandboxCall(line=pkg.node_str(node), lineno=lineno + 1, pkg=pkg)
+
+
+class VariableOrderWrong(results.VersionResult, results.Style):
+ """Variable were defined in an unexpected error."""
+
+ def __init__(self, first_var, second_var, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.first_var = first_var
+ self.second_var = second_var
+
+ @property
+ def desc(self):
+ return f"variable {self.first_var} should occur before {self.second_var}"
+
+
+class VariableOrderCheck(Check):
+ """Scan ebuilds for variables defined in a different order than skel.ebuild dictates."""
+
+ _source = sources.EbuildParseRepoSource
+ known_results = frozenset({VariableOrderWrong})
+
+ # Order from skel.ebuild
+ variable_order = (
+ "DESCRIPTION",
+ "HOMEPAGE",
+ "SRC_URI",
+ "S",
+ "LICENSE",
+ "SLOT",
+ "KEYWORDS",
+ "IUSE",
+ "RESTRICT",
+ )
+
+ def feed(self, pkg: bash.ParseTree):
+ var_assigns = []
+
+ for node in pkg.tree.root_node.children:
+ if node.type == "variable_assignment":
+ used_name = pkg.node_str(node.child_by_field_name("name"))
+ if used_name in self.variable_order:
+ var_assigns.append(used_name)
+
+ index = 0
+ for first_var in var_assigns:
+ if first_var in self.variable_order:
+ new_index = self.variable_order.index(first_var)
+ if new_index < index:
+ yield VariableOrderWrong(first_var, self.variable_order[index], pkg=pkg)
+ index = new_index