|
4 | 4 | """
|
5 | 5 |
|
6 | 6 | import argparse
|
7 |
| -from collections import defaultdict |
8 | 7 | import re
|
9 | 8 | import sys
|
| 9 | +from collections import defaultdict |
10 | 10 | from pathlib import Path
|
11 | 11 | from typing import NamedTuple
|
12 | 12 |
|
@@ -38,7 +38,8 @@ def parse_warning_ignore_file(file_path: str) -> set[IgnoreRule]:
|
38 | 38 | # Directories must have a wildcard count
|
39 | 39 | if is_directory and count != "*":
|
40 | 40 | print(
|
41 |
| - f"Error parsing ignore file: {file_path} at line: {i}" |
| 41 | + f"Error parsing ignore file: {file_path} " |
| 42 | + f"at line: {i}" |
42 | 43 | )
|
43 | 44 | print(
|
44 | 45 | f"Directory {file_name} must have count set to *"
|
@@ -93,9 +94,10 @@ def extract_warnings_from_compiler_output(
|
93 | 94 | .rstrip("]"),
|
94 | 95 | }
|
95 | 96 | )
|
96 |
| - except: |
| 97 | + except AttributeError: |
97 | 98 | print(
|
98 |
| - f"Error parsing compiler output. Unable to extract warning on line {i}:\n{line}" |
| 99 | + f"Error parsing compiler output. " |
| 100 | + f"Unable to extract warning on line {i}:\n{line}" |
99 | 101 | )
|
100 | 102 | sys.exit(1)
|
101 | 103 |
|
@@ -125,8 +127,9 @@ def get_warnings_by_file(warnings: list[dict]) -> dict[str, list[dict]]:
|
125 | 127 | def is_file_ignored(
|
126 | 128 | file_path: str, ignore_rules: set[IgnoreRule]
|
127 | 129 | ) -> IgnoreRule | None:
|
128 |
| - """ |
129 |
| - Returns the IgnoreRule object for the file path if there is a related rule for it |
| 130 | + """Return the IgnoreRule object for the file path. |
| 131 | +
|
| 132 | + Return ``None`` if there is no related rule for that path. |
130 | 133 | """
|
131 | 134 | for rule in ignore_rules:
|
132 | 135 | if rule.is_directory:
|
@@ -191,7 +194,10 @@ def get_unexpected_improvements(
|
191 | 194 | """
|
192 | 195 | unexpected_improvements = []
|
193 | 196 | for rule in ignore_rules:
|
194 |
| - if not rule.ignore_all and rule.file_path not in files_with_warnings.keys(): |
| 197 | + if ( |
| 198 | + not rule.ignore_all |
| 199 | + and rule.file_path not in files_with_warnings.keys() |
| 200 | + ): |
195 | 201 | if rule.file_path not in files_with_warnings.keys():
|
196 | 202 | unexpected_improvements.append((rule.file_path, rule.count, 0))
|
197 | 203 | elif len(files_with_warnings[rule.file_path]) < rule.count:
|
|
0 commit comments