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

Class SourceChecks

tools/lint.py:237–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235 self.c = "\n".join(new_lines)
236
237class SourceChecks:
238 def __init__(self, c, path, cpp_class_map, fix=False, slow=False):
239 self.c = c
240 self.path = path
241 self.fix = fix
242 self.map = cpp_class_map
243 self.slow = slow
244
245 def run(self):
246 self.include_at_top()
247 if self.slow:
248 with open("src/Minecraft.Client/net/minecraft/client/ui/StringIDs.h", "r") as f:
249 self.string_ids(f.read())
250 return self.c
251
252 # checks if the include for the current file is at the top of the file with a newline after
253 def include_at_top(self):
254 include_path = self.path.split('/', 2)
255 include_path = include_path[2] if len(include_path) > 2 else self.path
256 include_path = include_path.replace('.cpp', '.h')
257 lines = self.c.splitlines()
258 new_lines = []
259 changed = False
260 include_found = False
261
262 for i, line in enumerate(lines):
263 original_line = line
264 if f'#include "{include_path}"' in line:
265 include_found = True
266 if i != 0:
267 FAIL(f'Include for "{include_path}" should be at the top of the file!', original_line, self.path)
268 # FIX
269 if self.fix:
270 new_lines.insert(0, f'#include "{include_path}"\n')
271 changed = True
272 continue # don't duplicate the line
273 new_lines.append(line)
274 else:
275 new_lines.append(line)
276
277 if changed:
278 self.c = "\n".join(new_lines)
279
280 def string_ids(self, id_file):
281 lines = self.c.splitlines()
282 new_lines = []
283 changed = False
284
285 for line in lines:
286 original_line = line
287
288 # 0xXXXXXXXX, signed, and unsigned ints
289 pattern = r'(0x[0-9A-Fa-f]{8}|\b-?\d+\b)'
290 matches = re.finditer(pattern, line)
291
292 for match in matches:
293 num_str = match.group(0)
294

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected