From 253986bc317314109fe72054c70e565588b25ba7 Mon Sep 17 00:00:00 2001 From: eivindt Date: Mon, 8 Apr 2019 18:10:40 +0200 Subject: [PATCH] List the number of violations per rule (#1786) * List the number of violations per rule * Avoid using 'id' as variable name --- addons/misra.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addons/misra.py b/addons/misra.py index f4fb7da69..ea1f1245d 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -2262,6 +2262,17 @@ else: if SHOW_SUMMARY: print("\nMISRA rule violations found: %s\n" % ("\t".join([ "%s: %d" % (viol, len(checker.get_violations(viol))) for viol in checker.get_violation_types()]))) + rules_violated = {} + for severity, ids in checker.get_violations(): + for misra_id in ids: + rules_violated[misra_id] = rules_violated.get(misra_id, 0) + 1 + print("Misra rules violated:") + convert = lambda text: int(text) if text.isdigit() else text + misra_sort = lambda key: [ convert(c) for c in re.split('[\.-]([0-9]*)', key) ] + for misra_id in sorted(rules_violated.keys(), key=misra_sort): + num = misra_id[len("misra-c2012-"):] + num = int(num[:num.index(".")]) * 100 + int(num[num.index(".")+1:]) + print("\t%15s (%s): %d" % (misra_id, checker.ruleTexts[num].severity, rules_violated[misra_id])) if args.show_suppressed_rules: checker.showSuppressedRules()