MCPcopy Create free account
hub / github.com/GRAnimated/MinecraftLCE / HeaderChecks

Class HeaderChecks

tools/lint.py:148–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146 self.c = "\n".join(new_lines)
147
148class HeaderChecks:
149 def __init__(self, c, path, cpp_class_map, fix=False, slow=False):
150 self.c = c
151 self.path = path
152 self.fix = fix
153 self.map = cpp_class_map
154
155 def run(self):
156 self.pragma_once()
157 self.newline_after_pragma()
158 self.virtual_override()
159 return self.c
160
161 def pragma_once(self):
162 lines = self.c.splitlines()
163 new_lines = []
164 changed = False
165 pragma_once_found = False
166
167 for line in lines:
168 original_line = line
169 if "#pragma once" in line:
170 pragma_once_found = True
171 new_lines.append(line)
172 elif line.strip().startswith("#include"):
173 if not pragma_once_found:
174 FAIL("Header files should start with '#pragma once'!", original_line, self.path)
175 # FIX
176 if self.fix:
177 new_lines.insert(0, "#pragma once\n")
178 changed = True
179 new_lines.append(line)
180 else:
181 new_lines.append(line)
182
183 if not pragma_once_found and not changed:
184 FAIL("Header files should start with '#pragma once'!", "", self.path)
185 # FIX
186 if self.fix:
187 new_lines.insert(0, "#pragma once\n")
188 changed = True
189
190 if changed:
191 self.c = "\n".join(new_lines)
192
193 def newline_after_pragma(self):
194 lines = self.c.splitlines()
195 new_lines = []
196 changed = False
197 pragma_once_found = False
198
199 for i, line in enumerate(lines):
200 original_line = line
201 if "#pragma once" in line:
202 pragma_once_found = True
203 new_lines.append(line)
204 if i + 1 < len(lines) and lines[i + 1].strip() != "":
205 FAIL("There should be a newline after '#pragma once'!", original_line, self.path)

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected