1 # See utils/checkpackagelib/readme.txt before editing this file.
2 # Kconfig generates errors if someone introduces a typo like "boool" instead of
3 # "bool", so below check functions don't need to check for things already
4 # checked by running "make menuconfig".
8 from base import _CheckFunction
9 from lib import ConsecutiveEmptyLines # noqa: F401
10 from lib import EmptyLastLine # noqa: F401
11 from lib import NewlineAtEof # noqa: F401
12 from lib import TrailingSpace # noqa: F401
15 def _empty_or_comment(text):
17 # ignore empty lines and comment lines indented or not
18 return line == "" or line.startswith("#")
21 def _part_of_help_text(text):
22 return text.startswith("\t ")
25 # used in more than one check
26 entries_that_should_not_be_indented = [
27 "choice", "comment", "config", "endchoice", "endif", "endmenu", "if",
28 "menu", "menuconfig", "source"]
31 class AttributesOrder(_CheckFunction):
32 attributes_order_convention = {
33 "bool": 1, "prompt": 1, "string": 1, "default": 2, "depends": 3,
34 "select": 4, "help": 5}
39 def check_line(self, lineno, text):
40 if _empty_or_comment(text) or _part_of_help_text(text):
43 attribute = text.split()[0]
45 if attribute in entries_that_should_not_be_indented:
48 if attribute not in self.attributes_order_convention.keys():
50 new_state = self.attributes_order_convention[attribute]
51 wrong_order = self.state > new_state
53 # save to process next line
54 self.state = new_state
57 return ["{}:{}: attributes order: type, default, depends on,"
58 " select, help ({}#_config_files)"
59 .format(self.filename, lineno, self.url_to_manual),
63 class HelpText(_CheckFunction):
64 HELP_TEXT_FORMAT = re.compile("^\t .{,62}$")
65 URL_ONLY = re.compile("^(http|https|git)://\S*$")
68 self.help_text = False
70 def check_line(self, lineno, text):
71 if _empty_or_comment(text):
74 entry = text.split()[0]
76 if entry in entries_that_should_not_be_indented:
77 self.help_text = False
79 if text.strip() == "help":
83 if not self.help_text:
86 if self.HELP_TEXT_FORMAT.match(text.rstrip()):
88 if self.URL_ONLY.match(text.strip()):
90 return ["{}:{}: help text: <tab><2 spaces><62 chars>"
91 " ({}#writing-rules-config-in)"
92 .format(self.filename, lineno, self.url_to_manual),
94 "\t " + "123456789 " * 6 + "12"]
97 class Indent(_CheckFunction):
98 ENDS_WITH_BACKSLASH = re.compile(r"^[^#].*\\$")
99 entries_that_should_be_indented = [
100 "bool", "default", "depends", "help", "prompt", "select", "string"]
103 self.backslash = False
105 def check_line(self, lineno, text):
106 if _empty_or_comment(text) or _part_of_help_text(text):
107 self.backslash = False
110 entry = text.split()[0]
112 last_line_ends_in_backslash = self.backslash
114 # calculate for next line
115 if self.ENDS_WITH_BACKSLASH.search(text):
116 self.backslash = True
118 self.backslash = False
120 if last_line_ends_in_backslash:
121 if text.startswith("\t"):
123 return ["{}:{}: continuation line should be indented using tabs"
124 .format(self.filename, lineno),
127 if entry in self.entries_that_should_be_indented:
128 if not text.startswith("\t{}".format(entry)):
129 return ["{}:{}: should be indented with one tab"
130 " ({}#_config_files)"
131 .format(self.filename, lineno, self.url_to_manual),
133 elif entry in entries_that_should_not_be_indented:
134 if not text.startswith(entry):
135 return ["{}:{}: should not be indented"
136 .format(self.filename, lineno),