diff --git a/utils/checkpackagelib/lib_config.py b/utils/checkpackagelib/lib_config.py index bf975d7a3b..202baa7f1b 100644 --- a/utils/checkpackagelib/lib_config.py +++ b/utils/checkpackagelib/lib_config.py @@ -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") diff --git a/utils/checkpackagelib/test_lib_config.py b/utils/checkpackagelib/test_lib_config.py index 474d17105e..35614ef152 100644 --- a/utils/checkpackagelib/test_lib_config.py +++ b/utils/checkpackagelib/test_lib_config.py @@ -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',