Main entry point for unified C++ linting.
()
| 840 | |
| 841 | |
| 842 | def main() -> int: |
| 843 | """Main entry point for unified C++ linting.""" |
| 844 | import argparse |
| 845 | |
| 846 | parser = argparse.ArgumentParser( |
| 847 | description="Run unified C++ linting checks on all files or a single file" |
| 848 | ) |
| 849 | parser.add_argument( |
| 850 | "file", nargs="?", help="Optional: single file to check (faster)" |
| 851 | ) |
| 852 | parser.add_argument( |
| 853 | "--rust", |
| 854 | action="store_true", |
| 855 | help="Use the Rust linter for the checker subset it currently supports", |
| 856 | ) |
| 857 | args = parser.parse_args() |
| 858 | rust_ab = os.environ.get("FL_LINT_AB") == "1" |
| 859 | use_rust_fast_path = args.rust and not rust_ab |
| 860 | |
| 861 | if args.file: |
| 862 | # Single file mode |
| 863 | file_path = Path(args.file).resolve() |
| 864 | if not file_path.exists(): |
| 865 | print(f"Error: File not found: {file_path}") |
| 866 | return 1 |
| 867 | |
| 868 | print(f"Running unified C++ linting checks on single file...") |
| 869 | print(f"File: {file_path}") |
| 870 | print() |
| 871 | |
| 872 | # Collect all headers for cross-file validation (even in single-file mode) |
| 873 | files_by_dir = collect_all_files_by_directory() |
| 874 | all_headers = _collect_all_headers(files_by_dir) |
| 875 | |
| 876 | # Create all checker instances |
| 877 | checkers_by_scope = create_checkers(all_headers=all_headers) |
| 878 | rust_results: dict[str, CheckerResults] = {} |
| 879 | if use_rust_fast_path: |
| 880 | rust_results = run_rust_linter([str(file_path)]) |
| 881 | remove_rust_supported_checkers(checkers_by_scope) |
| 882 | |
| 883 | # Run all applicable checkers on the single file |
| 884 | results = run_checkers_on_single_file(str(file_path), checkers_by_scope) |
| 885 | merge_checker_results(results, rust_results) |
| 886 | |
| 887 | # Run targeted unity build check for .cpp.hpp files and build files in src/fl/build/ |
| 888 | is_build_file = "/fl/build/" in str(file_path).replace("\\", "/") |
| 889 | if file_path.name.endswith(".cpp.hpp") or is_build_file: |
| 890 | unity_result = check_unity_build_single_file(file_path) |
| 891 | if not unity_result.success: |
| 892 | unity_checker_results = CheckerResults() |
| 893 | for violation in unity_result.violations: |
| 894 | unity_checker_results.add_violation( |
| 895 | "unity_build_structure", 0, violation |
| 896 | ) |
| 897 | results["UnityBuildChecker"] = unity_checker_results |
| 898 | |
| 899 | # Run targeted test aggregation check for test .cpp/.hpp files |
no test coverage detected