| 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() |