Arshad
2 min readNov 24, 2020

Lizard — a Cyclomatic Complexity Analyzer

Lizard is an extensible Cyclomatic Complexity Analyzer. It also does copy-paste detection (code clone detection/code duplicate detection) and many other forms of static code analysis.

Its been used in our favorites tools like below

What is Cyclomatic Complexity?

It is a software metric used to indicate the complexity of a program. Cyclomatic complexity of a code section is the quantitative measure of the number of linearly independent paths in it. It is computed using the Control Flow Graph of the program.

For example, if code contains no control flow statement then its cyclomatic complexity will be 1 and source code contains a single path in it.

If the code contains one if condition then cyclomatic complexity will be 2 as there will be 2 paths one for true and other for false.

Lizard features

  • It counts the nloc (lines of code without comments),
  • CCN (cyclomatic complexity number),
  • It counts token count of functions.
  • It counts parameter count of functions.

List of supported languages by Lizard

  • Objective-C
  • Swift
  • C/C++
  • Java
  • C#
  • JavaScript
  • Python
  • Ruby
  • TTCN-3
  • PHP
  • Scala
  • GDScript
  • Golang
  • Lua
  • Rust

Installation

[sudo] pip install lizard

How to use it?

just run the below command under your project folder

lizard

You will get the output as below

A lot can be optimized as it comes with lots of customization. Some folder can be excluded too.

References

Arshad
Arshad

Written by Arshad

Mobile enthusiastic, iOS developer.

Responses (1)