Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit 2bb4869

Browse files
authored
Fix CodeQL warnings. (#51)
1 parent a626d70 commit 2bb4869

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

amarna/command_line.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from amarna.Result import Result, ResultMultiplePositions, output_result
55
from amarna.Result import SARIF_MODE, SUMMARY_MODE
66
from typing import List, Union
7+
import sys
78

89
example_usage = """---------------\nUsage examples\n---------------
910
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]:
4243
for rule in rules + excluded:
4344
if rule not in ALL_RULES:
4445
print("Unknown rule: " + repr(rule))
45-
exit(-1)
46+
sys.exit(-1)
4647

4748
if rules:
4849
base_rules = rules
@@ -84,7 +85,7 @@ def filter_results_from_disable(
8485
return new_results
8586

8687

87-
def main() -> None:
88+
def main() -> int:
8889
parser = argparse.ArgumentParser(
8990
description="Amarna is a static-analyzer for the Cairo programming language.",
9091
epilog=example_usage,
@@ -170,6 +171,8 @@ def main() -> None:
170171
if args.output or args.print:
171172
output_result(results, args.output, args.print, mode)
172173

174+
return 0
175+
173176

174177
if __name__ == "__main__":
175178
main()

amarna/rules/gatherer_rules/FunctionsEmittingEventsGatherer.py

+4
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ def get_gathered_data(self) -> List[FunctionEmittingEvent]:
3434
return self.functions_emitting_events
3535

3636
def code_element_function(self, tree: Tree) -> None:
37+
function_name = None
38+
3739
for child in tree.children:
3840
if child.data == "identifier_def":
3941
function_name = str(child.children[0])
4042
break
4143

44+
assert function_name != None
45+
4246
events_emitted_list: List[EventEmitType] = []
4347

4448
for call in tree.find_data("function_call"):

amarna/rules/local_rules/UnusedImportRule.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Set
1+
from typing import List, Set
22
from lark import Tree, Token
33
from amarna.Result import PositionType, create_result
44

@@ -56,21 +56,20 @@ def cairo_file(self, tree: Tree) -> None:
5656
return
5757

5858
# gather all hint code and check if the imports are there
59-
all_hints = ""
59+
all_hints: List[str] = []
6060
for hint in self.original_tree.find_data("code_element_hint"):
61-
all_hints += hint.children[0]
61+
all_hints.append(hint.children[0])
62+
63+
hints_str = "\n".join(all_hints)
6264

6365
# remove imports used in hints
6466
used_in_hints = set()
6567
for unused in unused_imports:
66-
if unused.value in all_hints:
68+
if unused.value in hints_str:
6769
used_in_hints.add(unused)
6870

6971
unused_imports = unused_imports - used_in_hints
7072

71-
# if unused_imports:
72-
# print(f"In file {self.fname}:")
73-
7473
# report unused imports
7574
for arg in sorted(unused_imports):
7675
# print(f"\t{arg.value} imported at line {arg.line}")

amarna/rules/post_process_rules/UnenforcedViewRule.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Dict, List
22
from amarna.Result import ResultMultiplePositions, result_multiple_positions
3-
from amarna.rules.GenericRule import GenericRule
43

54
from amarna.rules.gatherer_rules.DeclaredFunctionsGatherer import (
65
DeclaredFunctionsGatherer,
@@ -12,7 +11,7 @@
1211
)
1312

1413

15-
class UnenforcedViewRule(GenericRule):
14+
class UnenforcedViewRule:
1615
"""
1716
Find state modifications in functions with @view decorator.
1817
"""

0 commit comments

Comments
 (0)