cyclomatic_complexity wrong estimate ?
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- using version 0.38.0
- I searched for existing GitHub issues
Describe the bug
I might be missing something but this code:
func testCYC(bool: Bool) {
if bool {
print("it is true")
}
print("it is default")
}
has 2 paths of execution

and if we follow the cyclomatic complexity formula where M = E - N + 2*P, this produces M = 2. However when I change the cyclomatic_complexity warning to 1, no warning is displayed. I feel like SwiftLint treats this to have a complexity of 1 and I am not sure why.
Is this a bug ?
For the record: https://github.com/terryyin/lizard produces M = 2 for the same code snippet which is what I'd expect.
cyclomatic_complexity:
warning: 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Start with the cyclomatic_complexity rule, reproduce the report using the shown Swift function and warning threshold of 1, and trace how the rule counts branches. Done means the behavior matches the expected complexity and a regression test covers this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100