()
| 316 | |
| 317 | |
| 318 | def main() -> int: |
| 319 | import argparse |
| 320 | |
| 321 | parser = argparse.ArgumentParser( |
| 322 | description=( |
| 323 | "Clang-tidy rule: enforce FL_NOEXCEPT on platform functions. " |
| 324 | "Uses clang-query AST analysis for zero false positives." |
| 325 | ) |
| 326 | ) |
| 327 | parser.add_argument( |
| 328 | "--fix", |
| 329 | action="store_true", |
| 330 | help="Auto-fix: insert FL_NOEXCEPT into source files (default: check only)", |
| 331 | ) |
| 332 | args = parser.parse_args() |
| 333 | |
| 334 | clang_query = _find_clang_query() |
| 335 | if not clang_query: |
| 336 | print("ERROR: clang-query not found.") |
| 337 | print("Install LLVM: https://github.com/llvm/llvm-project/releases") |
| 338 | return 1 |
| 339 | |
| 340 | print(f"Using: {clang_query}") |
| 341 | print(f"Scope: src/platforms/") |
| 342 | print(f"Mode: {'fix' if args.fix else 'check'}") |
| 343 | print() |
| 344 | |
| 345 | # AST analysis |
| 346 | print("Running clang-query (AST analysis)...") |
| 347 | hits = _find_missing_noexcept(clang_query) |
| 348 | |
| 349 | if not hits: |
| 350 | print("\nAll functions have FL_NOEXCEPT. Nothing to do.") |
| 351 | return 0 |
| 352 | |
| 353 | # Group by file for display |
| 354 | by_file: dict[str, list[tuple[int, str]]] = {} |
| 355 | for filepath, line_num, line_text in hits: |
| 356 | by_file.setdefault(filepath, []).append((line_num, line_text)) |
| 357 | |
| 358 | print( |
| 359 | f"\nFound {len(hits)} functions missing FL_NOEXCEPT in {len(by_file)} files:\n" |
| 360 | ) |
| 361 | |
| 362 | if args.fix: |
| 363 | changes, files = _apply_fixes(hits, dry_run=False) |
| 364 | print(f"\nApplied {changes} changes across {files} files.") |
| 365 | return 0 |
| 366 | else: |
| 367 | # Check-only mode: print violations and exit with error |
| 368 | for filepath in sorted(by_file): |
| 369 | print(f"{filepath}:") |
| 370 | for line_num, line_text in sorted(by_file[filepath]): |
| 371 | print(f" Line {line_num}: {line_text}") |
| 372 | print() |
| 373 | |
| 374 | # Also show what --fix would do |
| 375 | print("--- Dry-run preview (use --fix to apply) ---\n") |
no test coverage detected