1 # See support/scripts/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 # Notice: ignore 'imported but unused' from pyflakes for check functions.
10 from lib import ConsecutiveEmptyLines
11 from lib import EmptyLastLine
12 from lib import NewlineAtEof
13 from lib import TrailingSpace
16 def _empty_or_comment(text):
18 # ignore empty lines and comment lines indented or not
19 return line == "" or line.startswith("#")
22 def _part_of_help_text(text):
23 return text.startswith("\t ")
26 # used in more than one check
27 entries_that_should_not_be_indented = [
28 "choice", "comment", "config", "endchoice", "endif", "endmenu", "if",
29 "menu", "menuconfig", "source"]
32 class AttributesOrder(_CheckFunction):
33 attributes_order_convention = {
34 "bool": 1, "prompt": 1, "string": 1, "default": 2, "depends": 3,
35 "select": 4, "help": 5}
40 def check_line(self, lineno, text):
41 if _empty_or_comment(text) or _part_of_help_text(text):
44 attribute = text.split()[0]
46 if attribute in entries_that_should_not_be_indented:
49 if attribute not in self.attributes_order_convention.keys():
51 new_state = self.attributes_order_convention[attribute]
52 wrong_order = self.state > new_state
54 # save to process next line
55 self.state = new_state
58 return ["{}:{}: attributes order: type, default, depends on,"
59 " select, help ({}#_config_files)"
60 .format(self.filename, lineno, self.url_to_manual),
64 class HelpText(_CheckFunction):
65 HELP_TEXT_FORMAT = re.compile("^\t .{,62}$")
66 URL_ONLY = re.compile("^(http|https|git)://\S*$")
69 self.help_text = False
71 def check_line(self, lineno, text):
72 if _empty_or_comment(text):
75 entry = text.split()[0]
77 if entry in entries_that_should_not_be_indented:
78 self.help_text = False
80 if text.strip() == "help":
84 if not self.help_text:
87 if self.HELP_TEXT_FORMAT.match(text.rstrip()):
89 if self.URL_ONLY.match(text.strip()):
91 return ["{}:{}: help text: <tab><2 spaces><62 chars>"
92 " ({}#writing-rules-config-in)"
93 .format(self.filename, lineno, self.url_to_manual),
95 "\t " + "123456789 " * 6 + "12"]
98 class Indent(_CheckFunction):
99 ENDS_WITH_BACKSLASH = re.compile(r"^[^#].*\\$")
100 entries_that_should_be_indented = [
101 "bool", "default", "depends", "help", "prompt", "select", "string"]
104 self.backslash = False
106 def check_line(self, lineno, text):
107 if _empty_or_comment(text) or _part_of_help_text(text):
108 self.backslash = False
111 entry = text.split()[0]
113 last_line_ends_in_backslash = self.backslash
115 # calculate for next line
116 if self.ENDS_WITH_BACKSLASH.search(text):
117 self.backslash = True
119 self.backslash = False
121 if last_line_ends_in_backslash:
122 if text.startswith("\t"):
124 return ["{}:{}: continuation line should be indented using tabs"
125 .format(self.filename, lineno),
128 if entry in self.entries_that_should_be_indented:
129 if not text.startswith("\t{}".format(entry)):
130 return ["{}:{}: should be indented with one tab"
131 " ({}#_config_files)"
132 .format(self.filename, lineno, self.url_to_manual),
134 elif entry in entries_that_should_not_be_indented:
135 if not text.startswith(entry):
136 return ["{}:{}: should not be indented"
137 .format(self.filename, lineno),