Skip to content

Commit

Permalink
Fix validator skip logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed Dec 7, 2023
1 parent 3a02769 commit 3c6d748
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 34 deletions.
32 changes: 23 additions & 9 deletions .tools/validation/metadata_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,28 @@


@dataclass
class MetadataParseError:
class MetadataError:
file: Optional[str] = None

def prefix(self):
prefix = f"In {self.file}, "
return prefix

def message(self):
pass

def __str__(self):
return f"{self.prefix()} {self.message()}"


@dataclass
class MetadataParseError(MetadataError):
id: Optional[str] = None
language: Optional[str] = None
sdk_version: Optional[int] = None

def prefix(self):
prefix = f"In {self.file}, example {self.id}"
prefix = super().prefix() + f"example {self.id}"
if self.language:
prefix += f": {self.language}"
if self.sdk_version:
Expand All @@ -25,7 +39,7 @@ def message(self):
pass

def __str__(self):
return f"{self.prefix} {self.message()}"
return f"{self.prefix()} {self.message()}"


@dataclass
Expand Down Expand Up @@ -53,16 +67,16 @@ class MetadataErrors:
"""MyPy isn't catching list[Foo].append(list[Foo])"""

def __init__(self):
self._errors: list[MetadataParseError] = []
self._errors: list[MetadataError] = []

def append(self, item: MetadataParseError):
if not isinstance(item, MetadataParseError):
def append(self, item: MetadataError):
if not isinstance(item, MetadataError):
raise InvalidItemException(item)
if item in self._errors:
raise DuplicateItemException(item)
self._errors.append(item)

def extend(self, errors: Iterable[MetadataParseError]):
def extend(self, errors: Iterable[MetadataError]):
self._errors.extend(errors)

def maybe_extend(self, maybe_errors: K | Self) -> K | None:
Expand All @@ -71,10 +85,10 @@ def maybe_extend(self, maybe_errors: K | Self) -> K | None:
return None
return maybe_errors

def __getitem__(self, key: int) -> MetadataParseError:
def __getitem__(self, key: int) -> MetadataError:
return self._errors[key]

def __setitem__(self, key: int, value: MetadataParseError):
def __setitem__(self, key: int, value: MetadataError):
self._errors[key] = value

def __len__(self) -> int:
Expand Down
6 changes: 1 addition & 5 deletions .tools/validation/project_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ def check_files(root: Path, errors: MetadataErrors):
:return: The number of errors found in the scanned files.
"""
file_count = 0
for file_path in get_files(
root,
lambda path: path.suffix.lower() not in validator_config.EXT_LOOKUP
or path.name in validator_config.IGNORE_FILES,
):
for file_path in get_files(root, validator_config.skip):
file_count += 1
logger.info("\nChecking File: %s", file_path)

Expand Down
45 changes: 25 additions & 20 deletions .tools/validation/validator_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,33 @@

# Only files with these extensions are scanned.
EXT_LOOKUP = {
"c": "C",
"cpp": "C++",
"cs": "C#",
"go": "Go",
"html": "JavaScript",
"java": "Java",
"js": "JavaScript",
"kt": "Kotlin",
"php": "PHP",
"py": "Python",
"rb": "Ruby",
"rs": "Rust",
"swift": "Swift",
"ts": "TypeScript",
"sh": "AWS-CLI",
"cmd": "AWS-CLI",
"json": "JSON",
"yml": "YAML",
"yaml": "YAML",
"md": "Markdown",
".c": "C",
".cpp": "C++",
".cs": "C#",
".go": "Go",
".html": "JavaScript",
".java": "Java",
".js": "JavaScript",
".kt": "Kotlin",
".php": "PHP",
".py": "Python",
".rb": "Ruby",
".rs": "Rust",
".swift": "Swift",
".ts": "TypeScript",
".sh": "AWS-CLI",
".cmd": "AWS-CLI",
".json": "JSON",
".yml": "YAML",
".yaml": "YAML",
".md": "Markdown",
}


def skip(path):
return path.suffix.lower() not in EXT_LOOKUP or path.name in IGNORE_FILES


# If you get a lot of false-flagged 40-character errors
# in specific folders or files, you can omit them from
# these scans by adding them to the following lists.
Expand Down

0 comments on commit 3c6d748

Please sign in to comment.