Skip to content

Commit 13f8e4b

Browse files
r-sharpt00sa
andcommitted
Unifying the style checkers (MetOffice#196)
* Yet another weird round of having to repeatedly accept the same changes which git / VS Code are marking as in conflict. Annoyingly, this seems to have introduced a bug as well. * Fixing issue with external runners not establishing properly. * Fixing an error that seems to have crept in during merging main and resolving clashes. But looking at it, I really can't fathom out 'how' * Where do these line length errors in the linter(s) come from - I haven't edited this file... * quick "improvement" to the error reporting in one of the tests * Why am I constantly having to re-impliment fixes/tidying I'm sure I've done before. * And now ruff_format wants to change them back again... * reviewer suggestion : start enumeration at 1 Co-authored-by: Sam Clarke-Green <74185251+t00sa@users.noreply.github.com> * reviewer suggestion : start enumeration at 1, remove +1 from log Co-authored-by: Sam Clarke-Green <74185251+t00sa@users.noreply.github.com> * Reviewer suggested changes : "Default mutable instance in a function signature" --------- Co-authored-by: Sam Clarke-Green <74185251+t00sa@users.noreply.github.com>
1 parent 5399708 commit 13f8e4b

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

script_umdp3_checker/umdp3_checker_rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def lowercase_variable_names(self, lines: List[str]) -> TestResult:
329329
failures = 0
330330
error_log = {}
331331
count = -1
332-
for count, line in enumerate(lines):
332+
for count, line in enumerate(lines, 1):
333333
clean_line = self.remove_quoted(line)
334334
clean_line = re.sub(r"!.*$", "", clean_line)
335335

@@ -348,7 +348,7 @@ def lowercase_variable_names(self, lines: List[str]) -> TestResult:
348348
self.add_extra_error(f"UPPERCASE variable name : {match[1]}")
349349
failures += 1
350350
error_log = self.add_error_log(
351-
error_log, f"UPPERCASE variable name {match[1]}", count + 1
351+
error_log, f"UPPERCASE variable name {match[1]}", count
352352
)
353353

354354
output = f"Checked {count + 1} lines, found {failures} failures."

script_umdp3_checker/umdp3_conformance.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import subprocess
22
from abc import ABC, abstractmethod
33
from pathlib import Path
4-
from typing import Callable, List, Dict, Set
4+
from typing import Callable, List, Dict, Set, Optional
55
from dataclasses import dataclass, field
66
import argparse
77
from checker_dispatch_tables import CheckerDispatchTables
@@ -165,14 +165,11 @@ def check(self, file_path: Path) -> CheckResult:
165165
def from_full_list(
166166
cls,
167167
name: str,
168-
file_extensions: Set[str] = set(),
169-
check_functions: Dict[str, Callable] = {},
170-
changed_files: List[Path] = [],
168+
file_extensions: Set[str],
169+
check_functions: Dict[str, Callable],
170+
changed_files: List[Path],
171171
print_volume: int = 3,
172172
):
173-
"""Create a StyleChecker instance whilst simultaneously filtering files
174-
from a full list.
175-
Returns a StyleChecker instance."""
176173
files_to_check = (
177174
cls.filter_files(changed_files, file_extensions) if changed_files else []
178175
)
@@ -188,7 +185,7 @@ def from_full_list(
188185

189186
@staticmethod
190187
def filter_files(
191-
files: List[Path], file_extensions: Set[str] = set()
188+
files: List[Path], file_extensions: Optional[Set[str]] = None
192189
) -> List[Path]:
193190
"""Filter files based on the checker's file extensions."""
194191
if not file_extensions:
@@ -201,7 +198,7 @@ def create_external_runners(
201198
name: str,
202199
commands: List[List[str]],
203200
all_files: List[Path],
204-
file_extensions: Set[str] = set(),
201+
file_extensions: Set[str],
205202
) -> "StyleChecker":
206203
"""Create a StyleChecker instance filtering files from a full list."""
207204
filtered_files = cls.filter_files(all_files, file_extensions)

0 commit comments

Comments
 (0)