diff --git a/amarna/command_line.py b/amarna/command_line.py index 53ede46..8bf04a7 100644 --- a/amarna/command_line.py +++ b/amarna/command_line.py @@ -4,6 +4,7 @@ from amarna.Result import Result, ResultMultiplePositions, output_result from amarna.Result import SARIF_MODE, SUMMARY_MODE from typing import List, Union +import sys example_usage = """---------------\nUsage examples\n--------------- Analyze a Cairo project in the current directory and export results to a file: @@ -42,7 +43,7 @@ def get_rule_names(rules: str, excluded: str) -> List[str]: for rule in rules + excluded: if rule not in ALL_RULES: print("Unknown rule: " + repr(rule)) - exit(-1) + sys.exit(-1) if rules: base_rules = rules @@ -84,7 +85,7 @@ def filter_results_from_disable( return new_results -def main() -> None: +def main() -> int: parser = argparse.ArgumentParser( description="Amarna is a static-analyzer for the Cairo programming language.", epilog=example_usage, @@ -170,6 +171,8 @@ def main() -> None: if args.output or args.print: output_result(results, args.output, args.print, mode) + return 0 + if __name__ == "__main__": main() diff --git a/amarna/rules/gatherer_rules/FunctionsEmittingEventsGatherer.py b/amarna/rules/gatherer_rules/FunctionsEmittingEventsGatherer.py index 41ed88c..9dc8244 100644 --- a/amarna/rules/gatherer_rules/FunctionsEmittingEventsGatherer.py +++ b/amarna/rules/gatherer_rules/FunctionsEmittingEventsGatherer.py @@ -34,11 +34,15 @@ def get_gathered_data(self) -> List[FunctionEmittingEvent]: return self.functions_emitting_events def code_element_function(self, tree: Tree) -> None: + function_name = None + for child in tree.children: if child.data == "identifier_def": function_name = str(child.children[0]) break + assert function_name != None + events_emitted_list: List[EventEmitType] = [] for call in tree.find_data("function_call"): diff --git a/amarna/rules/local_rules/UnusedImportRule.py b/amarna/rules/local_rules/UnusedImportRule.py index 3c4f6d6..b282a8e 100644 --- a/amarna/rules/local_rules/UnusedImportRule.py +++ b/amarna/rules/local_rules/UnusedImportRule.py @@ -1,4 +1,4 @@ -from typing import Set +from typing import List, Set from lark import Tree, Token from amarna.Result import PositionType, create_result @@ -56,21 +56,20 @@ def cairo_file(self, tree: Tree) -> None: return # gather all hint code and check if the imports are there - all_hints = "" + all_hints: List[str] = [] for hint in self.original_tree.find_data("code_element_hint"): - all_hints += hint.children[0] + all_hints.append(hint.children[0]) + + hints_str = "\n".join(all_hints) # remove imports used in hints used_in_hints = set() for unused in unused_imports: - if unused.value in all_hints: + if unused.value in hints_str: used_in_hints.add(unused) unused_imports = unused_imports - used_in_hints - # if unused_imports: - # print(f"In file {self.fname}:") - # report unused imports for arg in sorted(unused_imports): # print(f"\t{arg.value} imported at line {arg.line}") diff --git a/amarna/rules/post_process_rules/UnenforcedViewRule.py b/amarna/rules/post_process_rules/UnenforcedViewRule.py index 8553105..3f9bf0b 100644 --- a/amarna/rules/post_process_rules/UnenforcedViewRule.py +++ b/amarna/rules/post_process_rules/UnenforcedViewRule.py @@ -1,6 +1,5 @@ from typing import Dict, List from amarna.Result import ResultMultiplePositions, result_multiple_positions -from amarna.rules.GenericRule import GenericRule from amarna.rules.gatherer_rules.DeclaredFunctionsGatherer import ( DeclaredFunctionsGatherer, @@ -12,7 +11,7 @@ ) -class UnenforcedViewRule(GenericRule): +class UnenforcedViewRule: """ Find state modifications in functions with @view decorator. """