Skip to content

Commit fdcf83d

Browse files
committed
MissingEAPIBlankLine: make it optional
Requested by multiple devs, maybe in future we would improve logic, and un-optional it. Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 2f5ceb7 commit fdcf83d

5 files changed

Lines changed: 39 additions & 23 deletions

File tree

src/pkgcheck/checks/whitespace.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import NamedTuple
55

66
from .. import results, sources
7-
from . import Check
7+
from . import Check, OptionalCheck
88

99

1010
class _Whitespace(results.LinesResult, results.Style):
@@ -131,7 +131,6 @@ class WhitespaceCheck(Check):
131131
TrailingEmptyLine,
132132
NoFinalNewline,
133133
BadWhitespaceCharacter,
134-
MissingEAPIBlankLine,
135134
}
136135
)
137136

@@ -148,14 +147,8 @@ def feed(self, pkg):
148147
leading = []
149148
indent = []
150149
double_empty = []
151-
eapi_lineno = None
152150

153151
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-
159152
for match in self.bad_whitespace_regex.finditer(line):
160153
yield BadWhitespaceCharacter(
161154
repr(match.group("char")),
@@ -191,3 +184,23 @@ def feed(self, pkg):
191184
# Dealing with empty ebuilds is just paranoia
192185
if pkg.lines and not pkg.lines[-1].endswith("\n"):
193186
yield NoFinalNewline(pkg=pkg)
187+
188+
189+
class MissingWhitespaceCheck(OptionalCheck):
190+
"""Scan ebuild for missing whitespace."""
191+
192+
_source = sources.EbuildFileRepoSource
193+
known_results = frozenset(
194+
{
195+
MissingEAPIBlankLine,
196+
}
197+
)
198+
199+
def feed(self, pkg):
200+
eapi_lineno = None
201+
202+
for lineno, line in enumerate(pkg.lines, 1):
203+
if line.startswith("EAPI="):
204+
eapi_lineno = lineno
205+
elif eapi_lineno is not None and lineno == eapi_lineno + 1 and line != "\n":
206+
yield MissingEAPIBlankLine(pkg=pkg)

testdata/data/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/expected.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

testdata/data/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/fix.patch

Lines changed: 0 additions & 9 deletions
This file was deleted.

testdata/repos/standalone/WhitespaceCheck/MissingEAPIBlankLine/MissingEAPIBlankLine-0.ebuild

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/checks/test_whitespace.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,21 @@ def test_it(self):
150150

151151
reports = self.assertReports(self.check, fake_pkg)
152152
assert len(reports) == 4
153+
154+
155+
class TestMissingWhitespaceCheck(misc.ReportTestCase):
156+
check_kls = whitespace.MissingWhitespaceCheck
157+
check = whitespace.MissingWhitespaceCheck(None)
158+
159+
def test_it(self):
160+
fake_src = [
161+
"# This is a comment\n",
162+
"# This is a comment\n",
163+
"# This is a comment, and no blank line before EAPI\n",
164+
"EAPI=8\n",
165+
"inherit fake\n", # no blank line after EAPI=
166+
]
167+
fake_pkg = misc.FakePkg("dev-util/diffball-0.5", lines=fake_src)
168+
169+
r = self.assertReport(self.check, fake_pkg)
170+
assert isinstance(r, whitespace.MissingEAPIBlankLine)

0 commit comments

Comments
 (0)