From 1774fc60d9bf2047ddd587c621553b09938de274 Mon Sep 17 00:00:00 2001 From: Roman <2776447+rganz@users.noreply.github.com> Date: Mon, 14 Sep 2026 10:19:14 +0200 Subject: [PATCH] Count a ternary once in cyclomatic complexity _calculate_cyclomatic_complexity added two for any line holding a ternary, because two rules matched the same text: the statement test also fired on " if " anywhere in the line, and the ternary count then fired again for the same occurrence. The statement test now matches only a line that begins with "if ", leaving in-line occurrences to the ternary rule that already handles them. Measured on a probe project against this tree. A function whose only decision point is one ternary went from 3 to 2, which is the correct value for base 1 plus one branch. A function with if, and, elif, or, for, while and one ternary went from 9 to 8, hand counted as 8. No other decision point changes. This matters beyond the number because _check_complexity assigns critical severity above cyclomatic_critical, so the over-count can fail a CI gate for complexity a function does not have. --- addons/gdscript-linter/analyzer/checkers/function-checker.gd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/gdscript-linter/analyzer/checkers/function-checker.gd b/addons/gdscript-linter/analyzer/checkers/function-checker.gd index ab7cbcf..cc9eede 100644 --- a/addons/gdscript-linter/analyzer/checkers/function-checker.gd +++ b/addons/gdscript-linter/analyzer/checkers/function-checker.gd @@ -212,7 +212,9 @@ func _calculate_cyclomatic_complexity(body_lines: Array) -> int: continue # Count decision points - if trimmed.begins_with("if ") or " if " in trimmed: + # Only the statement form here. A line holding a ternary is counted by the + # ternary rule below, so matching " if " here as well counted it twice. + if trimmed.begins_with("if "): complexity += 1 if trimmed.begins_with("elif "): complexity += 1