Check if brackets are balanced in a file (after stripping comments). Args: file_path (Path): Path to the file to check Returns: bool: True if brackets are balanced, False otherwise
(file_path: Path)
| 58 | |
| 59 | |
| 60 | def is_bracket_balanced(file_path: Path) -> bool: |
| 61 | """ |
| 62 | Check if brackets are balanced in a file (after stripping comments). |
| 63 | |
| 64 | Args: |
| 65 | file_path (Path): Path to the file to check |
| 66 | |
| 67 | Returns: |
| 68 | bool: True if brackets are balanced, False otherwise |
| 69 | """ |
| 70 | try: |
| 71 | with open(file_path, "r", encoding="utf-8") as f: |
| 72 | content = f.read() |
| 73 | |
| 74 | # Strip comments first |
| 75 | content = strip_comments(content) |
| 76 | |
| 77 | # Count brackets |
| 78 | open_count = content.count("{") |
| 79 | close_count = content.count("}") |
| 80 | |
| 81 | return open_count == close_count |
| 82 | except (UnicodeDecodeError, IOError): |
| 83 | return True # Assume balanced if we can't read |
| 84 | |
| 85 | |
| 86 | def find_includes_after_namespace_thorough( |
no test coverage detected