-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: BACK-8055 Detect unused definitions
- Loading branch information
1 parent
488bc85
commit 90a55e1
Showing
2 changed files
with
29 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import final, override | ||
|
||
from erc7730.common.output import OutputAdder | ||
from erc7730.lint import ERC7730Linter | ||
from erc7730.model.resolved.context import ResolvedEIP712Context | ||
from erc7730.model.resolved.descriptor import ResolvedERC7730Descriptor | ||
|
||
|
||
@final | ||
class DefinitionLinter(ERC7730Linter): | ||
"""Check that parameters under definitions are used in formats section""" | ||
|
||
@override | ||
def lint(self, descriptor: ResolvedERC7730Descriptor, out: OutputAdder) -> None: | ||
if isinstance(descriptor.context, ResolvedEIP712Context) and descriptor.display.definitions is not None: | ||
for name, _ in descriptor.display.definitions.items(): | ||
found = False | ||
for _, format in descriptor.display.formats.items(): | ||
if found is False: | ||
for field in format.fields: | ||
if field.path == name: | ||
found = True | ||
if found is False: | ||
out.error( | ||
title="Unused field definition", | ||
message=f"Field {name} is not used in descriptor formats.", | ||
) |