@@ -18,8 +18,9 @@ class Defect:
1818
1919 Attributes:
2020 sast (str): The name of the SAST tool that reported the defect.
21- file (Path): The path to the file where the defect was found.
22- file_path (str): The string representation of the file path.
21+ filepath (Path): The path to the file where the defect was found.
22+ filepath_str (str): The string representation of the file path.
23+ filename (str): The name of the file.
2324 checker (str): The name of the checker or rule that reported the defect.
2425 category (str): The category of the checker (e.g., security, performance).
2526 cwe (CWE): The CWE associated with the defect.
@@ -33,7 +34,7 @@ class Defect:
3334
3435 def __init__ (
3536 self ,
36- file : Path ,
37+ filepath : Path ,
3738 checker : str ,
3839 category : str ,
3940 cwe : CWE ,
@@ -44,7 +45,7 @@ def __init__(
4445 """Initialize a Defect instance.
4546
4647 Args:
47- file : The file path of the defect.
48+ filepath : The file path of the defect.
4849 checker: The name of the rule/checker.
4950 category: The category of the checker.
5051 cwe: The CWE associated with the defect.
@@ -53,8 +54,9 @@ def __init__(
5354 data: Raw data from the SAST tool for this defect.
5455
5556 """
56- self .file = file
57- self .file_path = str (file )
57+ self .filepath = filepath
58+ self .filepath_str = str (filepath )
59+ self .filename = filepath .name
5860 self .checker = checker
5961 self .category = category
6062 self .cwe = cwe
@@ -206,9 +208,9 @@ def stats_by_checkers(self) -> dict:
206208 stats = {}
207209 for defect in self .defects :
208210 if defect .checker not in stats .keys ():
209- stats [defect .checker ] = {"count" : 1 , "files" : [defect .file_path ]}
211+ stats [defect .checker ] = {"count" : 1 , "files" : [defect .filepath_str ]}
210212 else :
211- stats [defect .checker ]["files" ].append (defect .file_path )
213+ stats [defect .checker ]["files" ].append (defect .filepath_str )
212214 stats [defect .checker ]["count" ] += 1
213215
214216 return stats
@@ -250,11 +252,11 @@ def stats_by_files(self) -> dict:
250252 """
251253 stats = {}
252254 for defect in self .defects :
253- if defect .file_path not in stats .keys ():
254- stats [defect .file_path ] = {"count" : 1 , "checkers" : [defect .checker ]}
255+ if defect .filepath_str not in stats .keys ():
256+ stats [defect .filepath_str ] = {"count" : 1 , "checkers" : [defect .checker ]}
255257 else :
256- stats [defect .file_path ]["checkers" ].append (defect .checker )
257- stats [defect .file_path ]["count" ] += 1
258+ stats [defect .filepath_str ]["checkers" ].append (defect .checker )
259+ stats [defect .filepath_str ]["count" ] += 1
258260
259261 return stats
260262
@@ -269,9 +271,9 @@ def stats_by_cwes(self) -> dict:
269271 stats = {}
270272 for defect in self .defects :
271273 if defect .cwe not in stats .keys ():
272- stats [defect .cwe ] = {"count" : 1 , "files" : [defect .file_path ]}
274+ stats [defect .cwe ] = {"count" : 1 , "files" : [defect .filepath_str ]}
273275 else :
274- stats [defect .cwe ]["files" ].append (defect .file_path )
276+ stats [defect .cwe ]["files" ].append (defect .filepath_str )
275277 stats [defect .cwe ]["count" ] += 1
276278
277279 return stats
0 commit comments