utils/check-package: add a check for 'default n' in Config.in files

Boolean Config.in symbols default to 'n', so we typically do not add such
redundant lines.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Julien Olivain <ju.o@free.fr>
(cherry picked from commit 279cbbdb64)
Signed-off-by: Thomas Perale <thomas.perale@mind.be>
This commit is contained in:
Peter Korsgaard
2025-11-12 12:06:43 +01:00
committed by Thomas Perale
parent c4de4c2a8f
commit 6b1d9ab4e7
2 changed files with 44 additions and 0 deletions

View File

@@ -242,6 +242,17 @@ class Indent(_CheckFunction):
text]
class NoDefaultN(_CheckFunction):
DEFAULTN = re.compile(r"^\tdefault n$")
def check_line(self, lineno, text):
text_nocomments = text.split("#")[0].rstrip()
if self.DEFAULTN.match(text_nocomments):
return ["{}:{}: boolean symbols default to 'n', so 'default n' is redundant"
.format(self.filename, lineno),
text]
class RedefinedConfig(_CheckFunction):
CONFIG = re.compile(r"^\s*(menu|)config\s+(BR2_\w+)\b")
IF = re.compile(r"^\s*if\s+([^#]*)\b")

View File

@@ -387,6 +387,39 @@ def test_Indent(testname, filename, string, expected):
assert warnings == expected
NoDefaultN = [
('good example',
'any',
'config BR2_PACKAGE_FOO\n'
'\tdefault y\n',
[]),
('default n',
'any',
'config BR2_PACKAGE_FOO\n'
'\tdefault n\n',
[['any:2: boolean symbols default to \'n\', so \'default n\' is redundant',
'\tdefault n\n']]),
('default n with comment',
'any',
'config BR2_PACKAGE_FOO\n'
'\tdefault n # this is a comment\n',
[['any:2: boolean symbols default to \'n\', so \'default n\' is redundant',
'\tdefault n # this is a comment\n']]),
('default n with trailing whitespace',
'any',
'config BR2_PACKAGE_FOO\n'
'\tdefault n \t\n',
[['any:2: boolean symbols default to \'n\', so \'default n\' is redundant',
'\tdefault n \t\n']])
]
@pytest.mark.parametrize('testname,filename,string,expected', NoDefaultN)
def test_NoDefaultN(testname, filename, string, expected):
warnings = util.check_file(m.NoDefaultN, filename, string)
assert warnings == expected
RedefinedConfig = [
('no redefinition',
'any',