Skip to content

Commit

Permalink
feat: BACK-8055 Detect unused definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaireGuerreGiordano committed Nov 22, 2024
1 parent f62f2b6 commit 32c7e3f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/erc7730/lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from erc7730.lint.lint_base import MultiLinter
from erc7730.lint.lint_transaction_type_classifier import ClassifyTransactionTypeLinter
from erc7730.lint.lint_validate_abi import ValidateABILinter
from erc7730.lint.lint_validate_definitions import DefinitionLinter
from erc7730.lint.lint_validate_display_fields import ValidateDisplayFieldsLinter
from erc7730.list.list import get_erc7730_files
from erc7730.model.input.descriptor import InputERC7730Descriptor
Expand Down Expand Up @@ -51,11 +52,7 @@ def lint_all(paths: list[Path], out: OutputAdder) -> int:
:return: number of files checked
"""
linter = MultiLinter(
[
ValidateABILinter(),
ValidateDisplayFieldsLinter(),
ClassifyTransactionTypeLinter(),
]
[ValidateABILinter(), ValidateDisplayFieldsLinter(), ClassifyTransactionTypeLinter(), DefinitionLinter()]
)

files = list(get_erc7730_files(*paths, out=out))
Expand Down
27 changes: 27 additions & 0 deletions src/erc7730/lint/lint_validate_definitions.py
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.",
)

0 comments on commit 32c7e3f

Please sign in to comment.