MCPcopy Create free account
hub / github.com/FastLED/FastLED / _apply_fixes

Function _apply_fixes

ci/refactor/add_fl_noexcept.py:397–460  ·  view source on GitHub ↗

Apply FL_NOEXCEPT insertions.

(hits: list[tuple[str, int]], apply: bool)

Source from the content-addressed store, hash-verified

395
396
397def _apply_fixes(hits: list[tuple[str, int]], apply: bool) -> FixResult:
398 """Apply FL_NOEXCEPT insertions."""
399 by_file: dict[str, list[int]] = {}
400 for filepath, line_num in hits:
401 by_file.setdefault(filepath, []).append(line_num)
402
403 total_changes = 0
404 total_files = 0
405 total_skipped = 0
406
407 for filepath in sorted(by_file):
408 full_path = PROJECT_ROOT / filepath
409 if not full_path.exists():
410 continue
411
412 content = full_path.read_text(encoding="utf-8", errors="replace")
413 lines = content.split("\n")
414 file_changes = 0
415 file_skipped = 0
416
417 # Collect all replacements first, then apply in reverse order
418 all_replacements: list[
419 tuple[int, str, int]
420 ] = [] # (line_idx, new_content, original_line_num)
421
422 for line_num in sorted(by_file[filepath]):
423 if line_num < 1 or line_num > len(lines):
424 continue
425
426 result = _insert_fl_noexcept_multiline(lines, line_num - 1)
427 if result is not None:
428 for line_idx, new_content in result:
429 all_replacements.append((line_idx, new_content, line_num))
430 file_changes += 1
431 else:
432 file_skipped += 1
433
434 if file_changes > 0:
435 if not apply:
436 # Dry-run: show what would change
437 for line_idx, new_content, orig_num in all_replacements:
438 print(f" {filepath}:{orig_num}")
439 print(f" - {lines[line_idx].strip()}")
440 print(f" + {new_content.strip()}")
441 else:
442 # Apply in reverse to preserve line numbers
443 for line_idx, new_content, _ in sorted(
444 all_replacements, key=lambda x: x[0], reverse=True
445 ):
446 lines[line_idx] = new_content
447
448 include_added = _ensure_include(lines)
449 full_path.write_text("\n".join(lines), encoding="utf-8")
450 print(
451 f" {filepath}: {file_changes} changes"
452 f"{' (+include)' if include_added else ''}"
453 )
454

Callers 1

mainFunction · 0.70

Calls 5

FixResultClass · 0.85
_ensure_includeFunction · 0.70
printFunction · 0.50
appendMethod · 0.45

Tested by

no test coverage detected