()
| 169 | |
| 170 | |
| 171 | def main(): |
| 172 | parser = argparse.ArgumentParser( |
| 173 | description="Check for 'using namespace' declarations in header files" |
| 174 | ) |
| 175 | parser.add_argument( |
| 176 | "--root", |
| 177 | type=Path, |
| 178 | default=PROJECT_ROOT / "src" / "fl", |
| 179 | help="Root directory to search (default: PROJECT_ROOT/src/fl)", |
| 180 | ) |
| 181 | parser.add_argument( |
| 182 | "--extensions", |
| 183 | nargs="+", |
| 184 | default=["h", "hpp", "hxx", "hh"], |
| 185 | help="Header file extensions to check (default: h hpp hxx hh)", |
| 186 | ) |
| 187 | parser.add_argument( |
| 188 | "--quiet", |
| 189 | action="store_true", |
| 190 | help="Only print violations, no summary messages", |
| 191 | ) |
| 192 | |
| 193 | args = parser.parse_args() |
| 194 | |
| 195 | if not args.quiet: |
| 196 | print(f"Checking for 'using namespace' declarations in {args.root}") |
| 197 | print(f"Extensions: {', '.join(args.extensions)}") |
| 198 | print() |
| 199 | |
| 200 | # Use the new FileContentChecker-based approach |
| 201 | root_dir = str(args.root) |
| 202 | extensions = [f".{ext}" for ext in args.extensions] |
| 203 | |
| 204 | # Collect files using collect_files_to_check |
| 205 | files_to_check = collect_files_to_check([root_dir], extensions=extensions) |
| 206 | |
| 207 | # Create checker and processor |
| 208 | checker = UsingNamespaceChecker() |
| 209 | processor = MultiCheckerFileProcessor() |
| 210 | |
| 211 | # Process all files in a single pass |
| 212 | processor.process_files_with_checkers(files_to_check, [checker]) |
| 213 | |
| 214 | # Get violations from checker |
| 215 | violations = checker.violations |
| 216 | |
| 217 | if violations: |
| 218 | if not args.quiet: |
| 219 | for file_path, line_info in violations.items(): |
| 220 | print(f"\n{file_path}:") |
| 221 | for line_num, line_content in line_info: |
| 222 | print(f" Line {line_num}: {line_content}") |
| 223 | print("\n❌ Found 'using namespace' declarations in header files!") |
| 224 | print("Consider moving these to implementation files (.cpp, .cc) or using") |
| 225 | print("specific 'using' declarations instead (e.g., 'using std::vector;')") |
| 226 | sys.exit(1) |
| 227 | else: |
| 228 | if not args.quiet: |
no test coverage detected