realm / realm/SwiftLint

cyclomatic_complexity wrong estimate ?

Open
#3,252 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
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

Screenshot 2020-06-26 at 19 00 10

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.