GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 13 / 0 / 13
Functions: 100.0% 3 / 0 / 3
Branches: 53.3% 16 / 0 / 30

src/linter/rules/TooManyParametersRule.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "TooManyParametersRule.h"
4
5 #include <ast/ASTNodes.h>
6
7 namespace spice::compiler {
8
9 // A caller has to hold this many arguments in mind (and their order) at every call site.
10 static constexpr size_t MAX_PARAM_COUNT = 6;
11
12 /**
13 * Emit a finding if the given parameter list has more entries than MAX_PARAM_COUNT.
14 *
15 * @param paramLst Parameter list of the function/procedure (nullptr if it has none)
16 * @param codeLoc Location to attach the finding to
17 * @param name Function/procedure name
18 * @param kindLabel "Function" or "Procedure", for the finding message
19 * @param ruleId Id of the rule producing the finding
20 * @param findings Findings vector to append to
21 */
22 8 static void checkParamCount(const ParamLstNode *paramLst, const CodeLoc &codeLoc, const std::string &name,
23 std::string_view kindLabel, std::string_view ruleId, std::vector<LintFinding> &findings) {
24
1/2
✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 4 not taken.
8 const size_t paramCount = paramLst != nullptr ? paramLst->params.size() : 0;
25
2/2
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 31 taken 7 times.
8 if (paramCount > MAX_PARAM_COUNT)
26
1/2
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 32 not taken.
1 findings.emplace_back(codeLoc, ruleId, LintSeverity::WARNING,
27
7/14
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 58 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 49 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 47 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 45 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 41 not taken.
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 39 not taken.
4 std::string(kindLabel) + " '" + name + "' has " + std::to_string(paramCount) + " parameters (max " +
28
3/6
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 63 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 37 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 35 not taken.
4 std::to_string(MAX_PARAM_COUNT) + "); consider grouping related parameters into a struct");
29 8 }
30
31 7 void TooManyParametersRule::checkFctDef(FctDefNode *node, std::vector<LintFinding> &findings) {
32
1/2
✓ Branch 4 → 5 taken 7 times.
✗ Branch 4 → 6 not taken.
7 checkParamCount(node->paramLst, node->codeLoc, node->name->name, "Function", id(), findings);
33 7 }
34
35 1 void TooManyParametersRule::checkProcDef(ProcDefNode *node, std::vector<LintFinding> &findings) {
36
1/2
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 6 not taken.
1 checkParamCount(node->paramLst, node->codeLoc, node->name->name, "Procedure", id(), findings);
37 1 }
38
39 } // namespace spice::compiler
40