Skip to content

Commit

Permalink
Use Finding class in Polyspace checker; Update test code quality reports
Browse files Browse the repository at this point in the history
  • Loading branch information
JokeWaumans committed Nov 20, 2024
1 parent a90861d commit 31fddbf
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 260 deletions.
34 changes: 10 additions & 24 deletions src/mlx/warnings/polyspace_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
from string import Template

from .code_quality import Finding
from .exceptions import WarningsConfigError
from .warnings_checker import WarningsChecker

Expand Down Expand Up @@ -215,44 +216,29 @@ def add_code_quality_finding(self, row):
Args:
row (dict): The row of the warning with the corresponding colomn names
'''
finding = {
"severity": "major",
"location": {
"path": self.cq_default_path,
"positions": {
"begin": {
"line": 1,
"column": 1
}
}
}
}

try:
description = self.cq_description_template.substitute(os.environ, **row)
except KeyError as err:
raise WarningsConfigError(f"Failed to find environment variable from configuration value "
f"'cq_description_template': {err}") from err

finding = Finding(description)
# Attention to bug finder: items have color red for impact: high, medium and low.
if row["information"].lower() in self.code_quality_severity.keys():
finding["severity"] = self.code_quality_severity[row["information"].lower()]
finding.severity = self.code_quality_severity[row["information"].lower()]
elif row["color"].lower() in self.code_quality_severity.keys():
finding["severity"] = self.code_quality_severity[row["color"].lower()]
finding.severity = self.code_quality_severity[row["color"].lower()]
else:
finding["severity"] = "info"
finding.severity = "info"

if row["file"]:
finding["location"]["path"] = row["file"]
finding.path = row["file"]
if "line" in row:
finding["location"]["positions"]["begin"]["line"] = int(row["line"])
finding.line = int(row["line"])
if "col" in row:
finding["location"]["positions"]["begin"]["column"] = int(row["col"])
finding["description"] = description
exclude = ("new", "status", "severity", "comment", "key")
row_without_key = [value for key, value in row.items() if key not in exclude]
finding["fingerprint"] = hashlib.md5(str(row_without_key).encode('utf-8')).hexdigest()
self.cq_findings.append(finding)
finding.column = int(row["col"])

self.cq_findings.append(finding.to_dict())

def check(self, content):
'''
Expand Down
2 changes: 2 additions & 0 deletions src/mlx/warnings/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from ruamel.yaml import YAML

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

args = parser.parse_args(args)
Finding.fingerprints = {} # Make sure the class variable is an empty dict
code_quality_enabled = bool(args.code_quality)
# Read config file
if args.configfile is not None:
Expand Down
Loading

0 comments on commit 31fddbf

Please sign in to comment.