diff --git a/slither/__main__.py b/slither/__main__.py index caaef5730..d303aebe6 100644 --- a/slither/__main__.py +++ b/slither/__main__.py @@ -335,6 +335,14 @@ def parse_args( default=defaults_flag_in_config["printers_to_run"], ) + group_printer.add_argument( + "--exclude-interfaces", + help= "Exclude interfaces from inheritance-graph printer", + action="store_true", + dest="exclude_interfaces", + default=False, + ) + group_detector.add_argument( "--list-detectors", help="List available detectors", diff --git a/slither/printers/inheritance/inheritance_graph.py b/slither/printers/inheritance/inheritance_graph.py index a16ce273a..3a91f1523 100644 --- a/slither/printers/inheritance/inheritance_graph.py +++ b/slither/printers/inheritance/inheritance_graph.py @@ -98,12 +98,14 @@ class PrinterInheritanceGraph(AbstractPrinter): """ ret = "" + inheritance = [i for i in contract.immediate_inheritance if "mock" not in i.name.lower()] + # Add arrows (number them if there is more than one path so we know order of declaration for inheritance). - if len(contract.immediate_inheritance) == 1: + if len(inheritance) == 1: immediate_inheritance = contract.immediate_inheritance[0] ret += f"c{contract.id}_{contract.name} -> c{immediate_inheritance.id}_{immediate_inheritance};\n" else: - for i, immediate_inheritance in enumerate(contract.immediate_inheritance): + for i, immediate_inheritance in enumerate(inheritance): ret += f'c{contract.id}_{contract.name} -> c{immediate_inheritance.id}_{immediate_inheritance} [ label="{i + 1}" ];\n' # Functions @@ -195,6 +197,8 @@ class PrinterInheritanceGraph(AbstractPrinter): content = 'digraph "" {\n' for c in self.contracts: + if c.is_top_level or "mock" in c.name.lower() or c.is_library or (self.slither.exclude_interfaces and c.is_interface): + continue content += self._summary(c) + "\n" content += "}" diff --git a/slither/slither.py b/slither/slither.py index 0f2218535..72cf36536 100644 --- a/slither/slither.py +++ b/slither/slither.py @@ -196,10 +196,12 @@ class Slither( if printers_to_run == "echidna": self.skip_data_dependency = True + # Used in inheritance-graph printer + self.exclude_interfaces = kwargs.get("exclude_interfaces", False) + self._init_parsing_and_analyses(kwargs.get("skip_analyze", False)) def _init_parsing_and_analyses(self, skip_analyze: bool) -> None: - for parser in self._parsers: try: parser.parse_contracts()