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

Function fix_file

ci/lint_cpp/noexcept_special_members_checker.py:406–475  ·  view source on GitHub ↗

Fix missing FL_NOEXCEPT in *path*. Returns ``(number_of_fixes, list_of_descriptions)``.

(path: Path, dry_run: bool = False)

Source from the content-addressed store, hash-verified

404
405
406def fix_file(path: Path, dry_run: bool = False) -> tuple[int, list[str]]:
407 """Fix missing FL_NOEXCEPT in *path*.
408
409 Returns ``(number_of_fixes, list_of_descriptions)``.
410 """
411 content = path.read_text(encoding="utf-8")
412 lines = content.split("\n")
413 class_names: set[str] = set(_CLASS_DEF.findall(content))
414 comment_mask = _compute_block_comment_mask(lines)
415
416 # (close_line_idx, close_col, kind)
417 fixes: list[tuple[int, int, str]] = []
418 skipped: list[tuple[int, str]] = []
419
420 for i, line in enumerate(lines):
421 stripped = line.strip()
422 if not stripped or stripped.startswith("//") or stripped.startswith("#"):
423 continue
424 if comment_mask[i]:
425 continue
426 if stripped.startswith("/*") or stripped.startswith("*"):
427 continue
428 if _SUPPRESS.search(line):
429 continue
430
431 info = classify_line(line, class_names)
432 if info is None:
433 # Try multi-line
434 joined = _join_multiline_signature(lines, i)
435 if joined:
436 info = classify_line(joined, class_names)
437 if info:
438 kind_ml = info[0]
439 idx_ml = line.index("(") if "(" in line else info[1]
440 info = (kind_ml, idx_ml)
441 if info is None:
442 continue
443 kind, open_paren = info
444
445 if signature_has_noexcept(lines, i, open_paren):
446 continue
447
448 # Find the closing ) position for the fix
449 cl, cc = _find_close_paren_multiline(lines, i, open_paren)
450 if cl >= 0:
451 fixes.append((cl, cc, kind))
452 else:
453 skipped.append((i + 1, kind))
454
455 if not fixes and not skipped:
456 return 0, []
457
458 descriptions: list[str] = []
459 for cl, cc, kind in fixes:
460 verb = "Would add" if dry_run else "Add"
461 descriptions.append(f" Line {cl + 1}: {verb} FL_NOEXCEPT to {kind}")
462 for line_num, kind in skipped:
463 descriptions.append(f" Line {line_num}: MANUAL: multi-line {kind}")

Callers 8

test_fix_destructorMethod · 0.90
test_fix_default_ctorMethod · 0.90
test_fix_copy_ctorMethod · 0.90
test_fix_move_assignMethod · 0.90
test_no_double_fixMethod · 0.90
test_adds_includeMethod · 0.90
mainFunction · 0.85

Calls 9

classify_lineFunction · 0.85
_insert_noexcept_atFunction · 0.85
signature_has_noexceptFunction · 0.70
_ensure_includeFunction · 0.70
setClass · 0.50
appendMethod · 0.45

Tested by 7

test_fix_destructorMethod · 0.72
test_fix_default_ctorMethod · 0.72
test_fix_copy_ctorMethod · 0.72
test_fix_move_assignMethod · 0.72
test_no_double_fixMethod · 0.72
test_adds_includeMethod · 0.72