GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 40.0% 8 / 1 / 21
Functions: 66.7% 2 / 0 / 3
Branches: 39.3% 11 / 0 / 28

src/linter/LintFinding.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "LintFinding.h"
4
5 #include <iostream>
6
7 #include <util/CodeLoc.h>
8 #include <util/GlobalDefinitions.h>
9
10 namespace spice::compiler {
11
12 /**
13 * Constructor
14 *
15 * @param codeLoc Code location, where the lint finding occurred
16 * @param ruleId Id of the rule that produced this finding, e.g. "naming-convention"
17 * @param severity Severity of the finding
18 * @param message Finding message suffix
19 */
20 5 LintFinding::LintFinding(const CodeLoc &codeLoc, const std::string_view ruleId, const LintSeverity severity, const std::string &message)
21
1/2
✓ Branch 4 → 5 taken 5 times.
✗ Branch 4 → 31 not taken.
15 : ruleId(ruleId), severity(severity) {
22
9/18
✓ Branch 7 → 8 taken 5 times.
✗ Branch 7 → 56 not taken.
✓ Branch 11 → 12 taken 5 times.
✗ Branch 11 → 48 not taken.
✓ Branch 12 → 13 taken 5 times.
✗ Branch 12 → 46 not taken.
✓ Branch 13 → 14 taken 5 times.
✗ Branch 13 → 44 not taken.
✓ Branch 14 → 15 taken 5 times.
✗ Branch 14 → 42 not taken.
✓ Branch 15 → 16 taken 5 times.
✗ Branch 15 → 40 not taken.
✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 38 not taken.
✓ Branch 17 → 18 taken 5 times.
✗ Branch 17 → 36 not taken.
✓ Branch 18 → 19 taken 5 times.
✗ Branch 18 → 34 not taken.
15 findingMessage = "[" + std::string(getSeverityLabel(severity)) + "] " + codeLoc.toPrettyString() + ": " + this->ruleId + ": " + message;
23 5 }
24
25 /**
26 * Print the lint finding to standard output
27 */
28 void LintFinding::print() const {
29 auto color = "\033[36m"; // INFO: cyan
30 if (severity == LintSeverity::WARNING)
31 color = "\033[33m"; // yellow
32 else if (severity == LintSeverity::ERROR)
33 color = "\033[31m"; // red
34 std::cout << color << findingMessage << "\033[0m\n";
35 }
36
37 /**
38 * Get the human-readable label for a lint severity
39 *
40 * @param severity Severity of the finding
41 * @return Label string for the severity
42 */
43 5 const char *LintFinding::getSeverityLabel(const LintSeverity severity) {
44
1/4
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 5 times.
✗ Branch 2 → 5 not taken.
✗ Branch 2 → 6 not taken.
5 switch (severity) {
45 case LintSeverity::INFO:
46 return "Info";
47 5 case LintSeverity::WARNING:
48 5 return "Lint";
49 case LintSeverity::ERROR:
50 return "Lint error";
51 }
52 assert_fail("Unknown lint severity"); // GCOV_EXCL_LINE
53 return "Unknown"; // GCOV_EXCL_LINE
54 }
55
56 } // namespace spice::compiler
57