Skip to content

Commit 2f5ceb7

Browse files
committed
MissingEAPIBlankLine: new check for missing blank after EAPI
Resolves: #570 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 7ca3a4b commit 2f5ceb7

54 files changed

Lines changed: 110 additions & 53 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ requires = [
99
"pathspec",
1010
"tree-sitter>=0.19.0",
1111
"snakeoil~=0.10.4",
12-
"pkgcore~=0.12.20",
12+
"pkgcore~=0.12.21",
1313
]
1414
build-backend = "setuptools.build_meta"
1515

@@ -41,7 +41,7 @@ dependencies = [
4141
"pathspec",
4242
"tree-sitter>=0.19.0",
4343
"snakeoil~=0.10.4",
44-
"pkgcore~=0.12.18",
44+
"pkgcore~=0.12.21",
4545
]
4646

4747
[project.optional-dependencies]

src/pkgcheck/checks/whitespace.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def desc(self):
7373
)
7474

7575

76+
class MissingEAPIBlankLine(results.VersionResult, results.Style):
77+
"""Missing blank line after ``EAPI=`` assignment."""
78+
79+
desc = "missing blank line after EAPI= assignment"
80+
81+
7682
class WhitespaceData(NamedTuple):
7783
"""Data format to register hardcoded list of bad whitespace characters."""
7884

@@ -118,14 +124,15 @@ class WhitespaceCheck(Check):
118124

119125
_source = sources.EbuildFileRepoSource
120126
known_results = frozenset(
121-
[
127+
{
122128
WhitespaceFound,
123129
WrongIndentFound,
124130
DoubleEmptyLine,
125131
TrailingEmptyLine,
126132
NoFinalNewline,
127133
BadWhitespaceCharacter,
128-
]
134+
MissingEAPIBlankLine,
135+
}
129136
)
130137

131138
_indent_regex = re.compile("^\t* \t+")
@@ -141,8 +148,14 @@ def feed(self, pkg):
141148
leading = []
142149
indent = []
143150
double_empty = []
151+
eapi_lineno = None
144152

145153
for lineno, line in enumerate(pkg.lines, 1):
154+
if line.startswith("EAPI="):
155+
eapi_lineno = lineno
156+
elif eapi_lineno is not None and lineno == eapi_lineno + 1 and line != "\n":
157+
yield MissingEAPIBlankLine(pkg=pkg)
158+
146159
for match in self.bad_whitespace_regex.finditer(line):
147160
yield BadWhitespaceCharacter(
148161
repr(match.group("char")),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"__class__": "BannedEapiCommand", "category": "BadCommandsCheck", "package": "BannedEapiCommand", "version": "0", "line": "dohtml doc/*", "lineno": 8, "command": "dohtml", "eapi": "7"}
1+
{"__class__": "BannedEapiCommand", "category": "BadCommandsCheck", "package": "BannedEapiCommand", "version": "0", "line": "dohtml doc/*", "lineno": 9, "command": "dohtml", "eapi": "7"}

testdata/data/repos/standalone/BadCommandsCheck/BannedEapiCommand/fix.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
diff -Naur standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-0.ebuild fixed/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-0.ebuild
22
--- standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-0.ebuild 2019-10-01 15:48:21.121467232 -0600
33
+++ fixed/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-0.ebuild 2019-10-01 15:50:51.970090195 -0600
4-
@@ -5,5 +5,6 @@
4+
@@ -6,5 +6,6 @@
55
LICENSE="BSD"
6-
6+
77
src_install() {
88
- dohtml doc/*
99
+ docinto html
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"__class__": "DeprecatedEapiCommand", "category": "BadCommandsCheck", "package": "DeprecatedEapiCommand", "version": "0", "line": "dohtml doc/*", "lineno": 8, "command": "dohtml", "eapi": "6"}
1+
{"__class__": "DeprecatedEapiCommand", "category": "BadCommandsCheck", "package": "DeprecatedEapiCommand", "version": "0", "line": "dohtml doc/*", "lineno": 9, "command": "dohtml", "eapi": "6"}

testdata/data/repos/standalone/BadCommandsCheck/DeprecatedEapiCommand/fix.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
diff -Naur standalone/BadCommandsCheck/DeprecatedEapiCommand/DeprecatedEapiCommand-0.ebuild fixed/BadCommandsCheck/DeprecatedEapiCommand/DeprecatedEapiCommand-0.ebuild
22
--- standalone/BadCommandsCheck/DeprecatedEapiCommand/DeprecatedEapiCommand-0.ebuild 2019-10-01 15:50:01.517881845 -0600
33
+++ fixed/BadCommandsCheck/DeprecatedEapiCommand/DeprecatedEapiCommand-0.ebuild 2019-10-01 15:51:40.877292175 -0600
4-
@@ -5,5 +5,6 @@
4+
@@ -6,5 +6,6 @@
55
LICENSE="BSD"
6-
6+
77
src_install() {
88
- dohtml doc/*
99
+ docinto html
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
diff -Naur standalone/EapiCheck/BannedEapi/BannedEapi-0.ebuild fixed/EapiCheck/BannedEapi/BannedEapi-0.ebuild
22
--- standalone/EapiCheck/BannedEapi/BannedEapi-0.ebuild 2019-09-15 03:05:12.832870282 -0600
33
+++ fixed/EapiCheck/BannedEapi/BannedEapi-0.ebuild 2019-09-15 03:11:08.602303656 -0600
4-
@@ -1,4 +1,4 @@
4+
@@ -1,5 +1,5 @@
55
-EAPI=1
66
+EAPI=7
7+
78
DESCRIPTION="Ebuild using banned EAPI"
89
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
910
SLOT="0"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
diff -Naur standalone/EapiCheck/DeprecatedEapi/DeprecatedEapi-0.ebuild fixed/EapiCheck/DeprecatedEapi/DeprecatedEapi-0.ebuild
22
--- standalone/EapiCheck/DeprecatedEapi/DeprecatedEapi-0.ebuild 2019-09-15 03:08:00.380545715 -0600
33
+++ fixed/EapiCheck/DeprecatedEapi/DeprecatedEapi-0.ebuild 2019-09-15 03:11:41.260435170 -0600
4-
@@ -1,4 +1,4 @@
4+
@@ -1,5 +1,5 @@
55
-EAPI=5
66
+EAPI=7
7+
78
DESCRIPTION="Ebuild using deprecated EAPI"
89
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
910
SLOT="0"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{"__class__": "EbuildUnquotedVariable", "category": "EbuildUnquotedVariablesCheck", "package": "EbuildUnquotedVariable", "version": "0", "variable": "FILESDIR", "lines": [9, 19]}
2-
{"__class__": "EbuildUnquotedVariable", "category": "EbuildUnquotedVariablesCheck", "package": "EbuildUnquotedVariable", "version": "0", "variable": "T", "lines": [25, 27, 41, 42]}
3-
{"__class__": "EbuildUnquotedVariable", "category": "EbuildUnquotedVariablesCheck", "package": "EbuildUnquotedVariable", "version": "0", "variable": "WORKDIR", "lines": [34]}
1+
{"__class__": "EbuildUnquotedVariable", "category": "EbuildUnquotedVariablesCheck", "package": "EbuildUnquotedVariable", "version": "0", "variable": "FILESDIR", "lines": [10, 20]}
2+
{"__class__": "EbuildUnquotedVariable", "category": "EbuildUnquotedVariablesCheck", "package": "EbuildUnquotedVariable", "version": "0", "variable": "T", "lines": [26, 28, 42, 43]}
3+
{"__class__": "EbuildUnquotedVariable", "category": "EbuildUnquotedVariablesCheck", "package": "EbuildUnquotedVariable", "version": "0", "variable": "WORKDIR", "lines": [35]}

testdata/data/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/fix.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild 2022-05-18 20:27:34.657647175 +0200
22
+++ fixed/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild 2022-05-18 20:50:00.271294657 +0200
3-
@@ -6,7 +6,7 @@
3+
@@ -7,7 +7,7 @@
44
S=${WORKDIR}/${PV} # ok
55

66
PATCHES=(
@@ -9,7 +9,7 @@
99
"${FILESDIR}"/foo.patch # ok
1010
"${FILESDIR}/foo.patch" # ok
1111
)
12-
@@ -16,28 +16,28 @@
12+
@@ -17,28 +17,28 @@
1313
:
1414
fi
1515

0 commit comments

Comments
 (0)