Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift complexity should include "guard" #575

Open
AndyDentFree opened this issue Jan 19, 2025 · 1 comment
Open

Swift complexity should include "guard" #575

AndyDentFree opened this issue Jan 19, 2025 · 1 comment

Comments

@AndyDentFree
Copy link

Describe the bug
The common guard statement is not handled. This is equivalent to an up-front test in C++ such as if (blah == nullptr) return;

A less-important addition would be to add defer which is equivalent to using the C++ RAII idiom but is simpler, with a statement rather than needing a helper class.

To Reproduce
I reviewed languages.json and noticed guard is missing.

Expected behavior
Count guard to add to complexity. It's a very common part of control flow in many Swift functions. It is often the only branch expression in a function.

Also suggest adding defer which is less common but can't see a reason not to add it as it's a reserved word.

Desktop:

  • OS: macOS
  • Version 3.4.0
@apocelipes
Copy link
Contributor

I do not think defer should be counted because defer does not generate any branch:

Image

The document says "always runs", so no conditions here.

I'll try to add guard, it actually generates branches. ? and catch should be counted too. AFAIK other complexity counting tools like lizard also count them.

apocelipes added a commit to apocelipes/scc that referenced this issue Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants