Skip to main content

Web Site Lizard

https://travis-ci.org/terryyin/lizard.png?branch=master https://badge.fury.io/py/lizard.svg

Lizard is an extensible Cyclomatic Complexity Analyzer for many programming languages including C/C++ (doesn’t require all the header files or Java imports). It also does copy-paste detection (code clone detection/code duplicate detection) and many other forms of static code analysis.

A list of supported languages:

  • C# (C Sharp)

  • C/C++ (works with C++14)

  • Erlang

  • Fortran

  • GDScript

  • Golang

  • Java

  • JavaScript (With ES6 and JSX)

  • Kotlin

  • Lua

  • Objective-C

  • Perl

  • PHP

  • PL/SQL

  • Python

  • R

  • Ruby

  • Rust

  • Scala

  • Solidity

  • Structured Text (St)

  • Swift

  • TTCN-3

  • TypeScript (With TSX)

  • VueJS

  • Zig

By default lizard will search for any source code that it knows and mix all the results together. This might not be what you want. You can use the “-l” option to select language(s).

It counts

  • the nloc (lines of code without comments),

  • CCN (cyclomatic complexity number),

  • token count of functions.

  • parameter count of functions.

You can set limitation for CCN (-C), the number of parameters (-a). Functions that exceed these limitations will generate warnings. The exit code of lizard will be none-Zero if there are warnings.

This tool actually calculates how complex the code ‘looks’ rather than how complex the code really ‘is’. People will need this tool because it’s often very hard to get all the included folders and files right when they are complicated. But we don’t really need that kind of accuracy for cyclomatic complexity.

It requires python3.8 or above (early versions are not verified).

Installation

lizard.py can be used as a stand alone Python script, most functionalities are there. You can always use it without any installation. To acquire all the functionalities of lizard, you will need a proper install.

python lizard.py

If you want a proper install:

[sudo] pip install lizard

Or if you’ve got the source:

[sudo] python setup.py install --prefix=/path/to/installation/directory/

Usage

lizard [options] [PATH or FILE] [PATH] ...

Run for the code under current folder (recursively):

lizard

Exclude anything in the tests folder:

lizard mySource/ -x"./tests/*"

Use .gitignore file:

lizard mySource/

If there is a .gitignore file in the given path, lizard will automatically use it as an additional filter to exclude files that match the gitignore patterns. This is useful when you want to analyze only the tracked files in your git repository. To analyze all discovered source files regardless of .gitignore, use –no-gitignore:

lizard --no-gitignore mySource/

Options

-h, --help            show this help message and exit
--version             show program's version number and exit
-l LANGUAGES, --languages LANGUAGES
                      List the programming languages you want to analyze. if left empty, it'll
                      search for all languages it knows. `lizard -l cpp -l java`searches for
                      C++ and Java code. The available languages are: cpp, java, csharp,
                      javascript, python, objectivec, ttcn, ruby, php, swift, scala, GDScript,
                      go, lua, rust, typescript, plsql
-V, --verbose         Output in verbose mode (long function name)
-C CCN, --CCN CCN     Threshold for cyclomatic complexity number warning. The default value is
                      15. Functions with CCN bigger than it will generate warning
-f INPUT_FILE, --input_file INPUT_FILE
                      get a list of filenames from the given file
-o OUTPUT_FILE, --output_file OUTPUT_FILE
                      Output file. The output format is inferred from the file extension (e.g.
                      .html), unless it is explicitly specified (e.g. using --xml).
-L LENGTH, --length LENGTH
                      Threshold for maximum function length warning. The default value is 1000.
                      Functions length bigger than it will generate warning
-a ARGUMENTS, --arguments ARGUMENTS
                      Limit for number of parameters
-w, --warnings_only   Show warnings only, using clang/gcc's warning format for printing
                      warnings. http://clang.llvm.org/docs/UsersManual.html#cmdoption-
                      fdiagnostics-format
--warning-msvs        Show warnings only, using Visual Studio's warning format for printing
                      warnings. https://msdn.microsoft.com/en-us/library/yxkt8b26.aspx
-i NUMBER, --ignore_warnings NUMBER
                      If the number of warnings is equal or less than the number, the tool will
                      exit normally; otherwise, it will generate error. If the number is
                      negative, the tool exits normally regardless of the number of warnings.
                      Useful in makefile for legacy code.
-x EXCLUDE, --exclude EXCLUDE
                      Exclude files that match the pattern. * matches everything, ? matches any
                      single character, "./folder/*" exclude everything in the folder
                      recursively. Multiple patterns can be specified. Don't forget to add ""
                      around the pattern.
--no-gitignore        Do not use .gitignore files to exclude files.
-t WORKING_THREADS, --working_threads WORKING_THREADS
                      number of working threads. The default value is 1. Using a bigger number
                      can fully utilize the CPU and often faster.
-X, --xml             Generate XML in cppncss style instead of the tabular output. Useful to
                      generate report in Jenkins server
--csv                 Generate CSV output as a transform of the default output
-H, --html            Output HTML report with interactive DataTables (sortable, searchable, filterable)
--checkstyle          Generate Checkstyle XML output for integration with Jenkins and other tools
-m, --modified        Calculate modified cyclomatic complexity number , which count a
                      switch/case with multiple cases as one CCN.
-E EXTENSIONS, --extension EXTENSIONS
                      User the extensions. The available extensions are: -Ecpre: it will ignore
                      code in the #else branch. -Ewordcount: count word frequencies and
                      generate tag cloud. -Eoutside: include the global code as one function.
                      -EIgnoreAssert: to ignore all code in assert. -ENS: count nested control
                      structures. -Ehalstead: compute Halstead complexity metrics. -Ecognitive:
                      compute Cognitive Complexity (SonarSource).
-s SORTING, --sort SORTING
                      Sort the warning with field. The field can be nloc,
                      cyclomatic_complexity, token_count, parameter_count, etc. Or an customized field.
-T THRESHOLDS, --Threshold THRESHOLDS
                      Set the limit for a field. The field can be nloc, cyclomatic_complexity,
                      token_count, parameter_count, etc. Or an customized file. Lizard will
                      report warning if a function exceed the limit
-W WHITELIST, --whitelist WHITELIST
                      The path and file name to the whitelist file. It's './whitelizard.txt' by
                      default. Find more information in README.

Example use

Analyze a folder recursively: lizard mahjong_game/src

==============================================================
  NLOC    CCN  token  param    function@line@file
--------------------------------------------------------------
    10      2     29      2    start_new_player@26@./html_game.c
   ...
     6      1      3      0    set_shutdown_flag@449@./httpd.c
    24      3     61      1    server_main@454@./httpd.c
--------------------------------------------------------------
2 file analyzed.
==============================================================
LOC    Avg.NLOC AvgCCN Avg.ttoken  function_cnt    file
--------------------------------------------------------------
    191     15      3        51        12     ./html_game.c
    363     24      4        86        15     ./httpd.c

======================================
!!!! Warnings (CCN > 15) !!!!
======================================
    66     19    247      1    accept_request@64@./httpd.c
=================================================================================
Total NLOC  Avg.NLOC  Avg CCN  Avg token  Fun Cnt  Warning cnt   Fun Rt   NLOC Rt
--------------------------------------------------------------------------------
       554        20     4.07      71.15       27            1      0.04    0.12

Warnings only (in clang/gcc formation):lizard -w mahjong_game

./src/html_ui/httpd.c:64: warning: accept_request has 19 CCN and 1 params (66 NLOC, 247 tokens)
./src/mahjong_game/mj_table.c:109: warning: mj_table_update_state has 20 CCN and 1 params (72 NLOC, 255 tokens)

Set warning threshold for any field:lizard -T nloc=25

The option -Tcyclomatic_complexity=10 is equal to -C10. The option -Tlength=10 is equal to -L10. The option -Tparameter_count=10 is equal to -a10.

You can also do -Tnloc=10 to set the limit of the NLOC. Any function that has NLOC greater than 10 will generate a warning.

Generated code

Lizard has a simple solution with generated code. Any code in a source file that is following a comment containing “GENERATED CODE” will be ignored completely. The ignored code will not generate any data, except the file counting.

Code Duplicate Detector

lizard -Eduplicate <path to your code>

Generate A Tag Cloud For Your Code

You can generate a “Tag cloud” of your code by the following command. It counts the identifiers in your code (ignoring the comments).

lizard -EWordCount <path to your code>

Cognitive Complexity

Cognitive Complexity (SonarSource, G. Ann Campbell) measures how hard a function is to understand rather than how many paths it has: a switch counts one no matter how many cases it has, a sequence of like logical operators (a && b && c) counts one, and control structures cost more the deeper they are nested. Enable it as an extension; it adds a CogC column, a --CogC warning threshold (15 by default) and a cognitive_complexity field usable with -s and -T:

lizard -Ecognitive <path to your code>
lizard -Ecognitive --CogC 25 -s cognitive_complexity <path to your code>

Nesting is followed for brace-delimited languages (C/C++, Java, C#, JavaScript/TypeScript, Go, Rust, Kotlin, Swift, PHP, …) and for Python; for the other languages the increments are counted without the nesting penalty. C preprocessor conditionals are not counted.

Using lizard as Python module

You can also use lizard as a Python module in your code:

>>> import lizard
>>> i = lizard.analyze_file("../cpputest/tests/AllTests.cpp")
>>> print i.__dict__
{'nloc': 9, 'function_list': [<lizard.FunctionInfo object at 0x10bf7af10>], 'filename': '../cpputest/tests/AllTests.cpp'}
>>> print i.function_list[0].__dict__
{'cyclomatic_complexity': 1, 'token_count': 22, 'name': 'main', 'parameter_count': 2, 'nloc': 3, 'long_name': 'main( int ac , const char ** av )', 'start_line': 30}

You can also use source code string instead of file. But you need to provide a file name (to identify the language).

>>> i = lizard.analyze_file.analyze_source_code("AllTests.cpp", "int foo(){}")

Whitelist

If for some reason you would like to ignore the warnings, you can use the whitelist. Add ‘whitelizard.txt’ to the current folder (or use -W to point to the whitelist file), then the functions defined in the file will be ignored. Please notice that if you assign the file pathname, it needs to be exactly the same relative path as Lizard to find the file. An easy way to get the file pathname is to copy it from the Lizard warning output. This is an example whitelist:

#whitelizard.txt
#The file name can only be whitelizard.txt and put it in the current folder.
#You may have commented lines begin with #.
function_name1, function_name2 # list function names in multiple lines or split with comma.
file/path/name:function1, function2  # you can also specify the filename

Options in Comments

You can use options in the comments of the source code to change the behavior of lizard. There are two types of forgiveness comments:

  1. Function forgiveness: Put “#lizard forgives” inside a function or before a function to suppress warnings for that function.

int foo() {
    // #lizard forgives
    ...
}

Selective forgiveness: Use "#lizard forgives(metric1, metric2)" to forgive only specific metrics (e.g. length, cyclomatic_complexity, parameter_count, nloc, token_count).
int foo() {
    // #lizard forgives(length)  // Forgive only length violations
    ...
}
  1. Global code forgiveness: Put “#lizard forgive global” before global code to suppress warnings for all code outside of functions.

// #lizard forgive global
int global_var = 0;
if (condition) {  // This complexity won't be counted
    ...
}

int foo() {  // Functions are still counted normally
    ...
}

Limitations

Lizard requires syntactically correct code. Upon processing input with incorrect or unknown syntax:

  • Lizard guarantees to terminate eventually (i.e., no forever loops, hangs) without hard failures (e.g., exit, crash, exceptions).

  • There is a chance of a combination of the following soft failures:

    • omission

    • misinterpretation

    • improper analysis / tally

    • success (the code under consideration is not relevant, e.g., global macros in C)

This approach makes the Lizard implementation simpler and more focused with partial parsers for various languages. Developers of Lizard attempt to minimize the possibility of soft failures. Hard failures are bugs in Lizard code, while soft failures are trade-offs or potential bugs.

In addition to asserting the correct code, Lizard may choose not to deal with some advanced or complicated language features:

  • C/C++ digraphs and trigraphs are not recognized.

  • C/C++ preprocessing or macro expansion is not performed. For example, using macro instead of parentheses (or partial statements in macros) can confuse Lizard’s bracket stacks.

  • Some C++ complicated templates may cause confusion with matching angle brackets and processing less-than < or more-than > operators inside of template arguments.

Literatures Referring to Lizard

Lizard is often used in software related researches. If you used it to support your work, you may contact the lizard author to add your work in the following list.

Lizard is also used as a plugin for fastlane to help check code complexity and submit xml report to sonar.

How To Contribute

Contributions are welcome. Project-specific development rules are in AGENTS.md. Adding a language reader uses .agents/skills/lizard-language-support/.

AI lifecycle guidance is installed under .agents/skills/ and .claude/skills/.

Metadata

Release files for lizard 1.24.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lizard 1.24.1
File Size Uploaded
lizard-1.24.1.tar.gz 112.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lizard 1.24.1
File Interpreter ABI Platform
lizard-1.24.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 234.5 kB

Release files / lizard-1.24.1.tar.gz

Download URL lizard-1.24.1.tar.gz
Size 112.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c022cf1aac8170994b175e2a700f0535088f66da7e6bdf6c59fbd3b716cd10ac
BLAKE2b-256 checksum
How to use checksums
05870352f911886e8b10b06b36dca674b9da91a25112bd08253b84346a1815e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / lizard-1.24.1-py2.py3-none-any.whl

Download URL lizard-1.24.1-py2.py3-none-any.whl
Size 122.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
746060a3e9a375af7340b2d4c6aab307b8a8b4199339c36ddc7afc4188b53d1c
BLAKE2b-256 checksum
How to use checksums
8b2d6e9562b7f3aa3f4e3b8899be26b4dbc67752340b2f63beeba441956aff58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.24.1 This release

2 release files

1.24.0

2 release files

1.22.2

2 release files

1.22.1

2 release files

1.22.0

2 release files

1.21.7

2 release files

1.21.6

2 release files

1.21.3

2 release files

1.20.0

2 release files

1.18.0

2 release files

1.17.9

2 release files

1.17.7

2 release files

1.17.6

2 release files

1.17.4

2 release files

1.17.1

1 release file

1.16.6

2 release files

1.16.5

2 release files

1.16.3

2 release files

1.16.2

2 release files

1.15.6

2 release files

1.15.5

2 release files

1.15.3

2 release files

1.15.2

2 release files

1.15.1

2 release files

1.14.9

2 release files

1.14.8

2 release files

1.14.7

2 release files

1.14.6

2 release files

1.14.5

2 release files

1.14.4

2 release files

1.14.2

2 release files

1.14.1

2 release files

1.14.0

2 release files

1.13.0

2 release files

1.12.14

1 release file

1.12.13

1 release file

1.12.12

1 release file

1.12.10

1 release file

1.12.9

1 release file

1.12.8

1 release file

1.12.7

1 release file

1.12.6

1 release file

1.12.5

2 release files

1.12.3

1 release file

1.11.0

2 release files

1.10.5

2 release files

1.10.4

2 release files

1.10.1

2 release files

1.10.0

2 release files

1.9.25

2 release files

1.9.24

2 release files

1.9.23

2 release files

1.9.22

2 release files

1.9.21

2 release files

1.9.18

1 release file

1.9.17

1 release file

1.9.16

1 release file

1.9.14

1 release file

1.9.13

1 release file

1.9.12

1 release file

1.9.11

1 release file

1.9.9

1 release file

1.9.8

1 release file

1.9.7

1 release file

1.9.6

1 release file

1.9.5

1 release file

1.9.4

1 release file

1.9.3

1 release file

1.9.2

1 release file

1.9.1

1 release file

1.9.0

1 release file

1.8.12

1 release file

1.8.11

1 release file

1.8.10

1 release file

1.8.9

1 release file

1.8.8

1 release file

1.8.7

1 release file

1.8.6

1 release file

1.8.4

1 release file

1.8.3

1 release file

1.8.2

1 release file

1.8.1

1 release file

1.8.0

1 release file

1.7.9

1 release file

1.7.8

1 release file

1.7.7

1 release file

1.7.6

1 release file

1.7.5

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page