Skip to content

Commit 31fddbf

Browse files
committed
Use Finding class in Polyspace checker; Update test code quality reports
1 parent a90861d commit 31fddbf

File tree

4 files changed

+248
-260
lines changed

4 files changed

+248
-260
lines changed

src/mlx/warnings/polyspace_checker.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
from string import Template
66

7+
from .code_quality import Finding
78
from .exceptions import WarningsConfigError
89
from .warnings_checker import WarningsChecker
910

@@ -215,44 +216,29 @@ def add_code_quality_finding(self, row):
215216
Args:
216217
row (dict): The row of the warning with the corresponding colomn names
217218
'''
218-
finding = {
219-
"severity": "major",
220-
"location": {
221-
"path": self.cq_default_path,
222-
"positions": {
223-
"begin": {
224-
"line": 1,
225-
"column": 1
226-
}
227-
}
228-
}
229-
}
230-
231219
try:
232220
description = self.cq_description_template.substitute(os.environ, **row)
233221
except KeyError as err:
234222
raise WarningsConfigError(f"Failed to find environment variable from configuration value "
235223
f"'cq_description_template': {err}") from err
236224

225+
finding = Finding(description)
237226
# Attention to bug finder: items have color red for impact: high, medium and low.
238227
if row["information"].lower() in self.code_quality_severity.keys():
239-
finding["severity"] = self.code_quality_severity[row["information"].lower()]
228+
finding.severity = self.code_quality_severity[row["information"].lower()]
240229
elif row["color"].lower() in self.code_quality_severity.keys():
241-
finding["severity"] = self.code_quality_severity[row["color"].lower()]
230+
finding.severity = self.code_quality_severity[row["color"].lower()]
242231
else:
243-
finding["severity"] = "info"
232+
finding.severity = "info"
244233

245234
if row["file"]:
246-
finding["location"]["path"] = row["file"]
235+
finding.path = row["file"]
247236
if "line" in row:
248-
finding["location"]["positions"]["begin"]["line"] = int(row["line"])
237+
finding.line = int(row["line"])
249238
if "col" in row:
250-
finding["location"]["positions"]["begin"]["column"] = int(row["col"])
251-
finding["description"] = description
252-
exclude = ("new", "status", "severity", "comment", "key")
253-
row_without_key = [value for key, value in row.items() if key not in exclude]
254-
finding["fingerprint"] = hashlib.md5(str(row_without_key).encode('utf-8')).hexdigest()
255-
self.cq_findings.append(finding)
239+
finding.column = int(row["col"])
240+
241+
self.cq_findings.append(finding.to_dict())
256242

257243
def check(self, content):
258244
'''

src/mlx/warnings/warnings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from ruamel.yaml import YAML
1414

15+
from .code_quality import Finding
1516
from .exceptions import WarningsConfigError
1617
from .junit_checker import JUnitChecker
1718
from .regex_checker import CoverityChecker, DoxyChecker, SphinxChecker, XMLRunnerChecker
@@ -277,6 +278,7 @@ def warnings_wrapper(args):
277278
help='Possible not-used flags from above are considered as command flags')
278279

279280
args = parser.parse_args(args)
281+
Finding.fingerprints = {} # Make sure the class variable is an empty dict
280282
code_quality_enabled = bool(args.code_quality)
281283
# Read config file
282284
if args.configfile is not None:

0 commit comments

Comments
 (0)