lizard

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.

https://github.com/terryyin/lizard

Science Score: 59.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
    Links to: iop.org
  • Committers with academic emails
    2 of 61 committers (3.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.7%) to scientific vocabulary

Keywords from Contributors

autograd distribution interactive serializer packaging charts network-simulation human uncertainty shellcodes
Last synced: 6 months ago · JSON representation

Repository

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.

Basic Info
  • Host: GitHub
  • Owner: terryyin
  • License: other
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 2.79 MB
Statistics
  • Stars: 2,028
  • Watchers: 55
  • Forks: 264
  • Open Issues: 53
  • Releases: 0
Created over 13 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog License

README.rst

|Web Site| Lizard
=================

.. image:: https://travis-ci.org/terryyin/lizard.png?branch=master
    :target: https://travis-ci.org/terryyin/lizard
.. image:: https://badge.fury.io/py/lizard.svg
    :target: https://badge.fury.io/py/lizard
.. |Web Site| image:: http://www.lizard.ws/website/static/img/logo-small.png
    :target: http://www.lizard.ws

|

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++ (works with C++14)
-  Java
-  C# (C Sharp)
-  JavaScript (With ES6 and JSX)
-  TypeScript (With TSX)
-  VueJS
-  Objective-C
-  Swift
-  Python
-  Ruby
-  TTCN-3
-  PHP
-  Scala
-  GDScript
-  Golang
-  Lua
-  Rust
-  Fortran
-  Kotlin
-  Solidity
-  Erlang
-  Zig
-  Perl

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.

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
  -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.
  -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
  --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.
  -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 


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 


Using lizard as Python module
-----------------------------

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

.. code:: python

    >>> import lizard
    >>> i = lizard.analyze_file("../cpputest/tests/AllTests.cpp")
    >>> print i.__dict__
    {'nloc': 9, 'function_list': [], '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).

.. code:: python

    >>> 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
       ...
   }

2. 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.

- Software Quality in the ATLAS experiment at CERN, which refers to Lizard as one of the tools, has been published in the Journal of Physics: http://iopscience.iop.org/article/10.1088/1742-6596/898/7/072011

    - S Martin-Haugh et al 2017 J. Phys.: Conf. Ser. 898 072011

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

- `fastlane-plugin-lizard `_
- `sonar `_
- `European research project FASTEN (Fine-grained Analysis of SofTware Ecosystems as Networks, `_
  - `for a quality analyzer `_

Owner

  • Name: Terry Yin
  • Login: terryyin
  • Kind: user
  • Location: Singapore
  • Company: @nerds-odd-e

Programmer and Supreme Leader @nerds-odd-e .

GitHub Events

Total
  • Issues event: 83
  • Watch event: 163
  • Delete event: 1
  • Issue comment event: 58
  • Push event: 101
  • Pull request event: 12
  • Fork event: 13
  • Create event: 23
Last Year
  • Issues event: 83
  • Watch event: 163
  • Delete event: 1
  • Issue comment event: 58
  • Push event: 101
  • Pull request event: 12
  • Fork event: 13
  • Create event: 23

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 1,028
  • Total Committers: 61
  • Avg Commits per committer: 16.852
  • Development Distribution Score (DDS): 0.245
Past Year
  • Commits: 158
  • Committers: 6
  • Avg Commits per committer: 26.333
  • Development Distribution Score (DDS): 0.082
Top Committers
Name Email Commits
Terry Yin t****y@o****m 776
rakhimov o****v@g****m 60
Mehrdad Mehraban m****d@g****m 23
GcsSloop G****p@g****m 13
Jakub Ostrzołek k****k@g****m 9
Antoine Cœur a****r@e****m 9
Marcus Medley m****s@g****m 8
Trevor Hall h****a@g****m 8
Sergey Bronnikov s****b@b****u 8
Corentin Plouet c****n@p****e 7
elmotec e****c@g****m 6
jason j****n@l****a 6
Frieder Bluemle f****e@g****m 6
JiahangLi j****i@u****u 6
FilipSzm F****i@s****l 6
Gustaf Johansson g****j@g****m 5
YASUE Kizuki i****k@k****p 4
peterSW p****s@g****m 4
yalechen y****n@t****m 4
gacekjk g****k@g****m 4
lijingda l****a@b****m 3
Arno Moonen a****n@a****m 3
dutchedge p****e@g****m 3
Janne Rönkkö j****o@v****i 3
John Maloney j****l@p****n 2
unknown y****n@y****m 2
David Baum s****k@g****m 2
shake551 h****o@g****m 2
dependabot[bot] 4****] 2
L. F. Pereira l****5@g****m 2
and 31 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 136
  • Total pull requests: 67
  • Average time to close issues: about 4 years
  • Average time to close pull requests: 4 months
  • Total issue authors: 93
  • Total pull request authors: 41
  • Average comments per issue: 2.02
  • Average comments per pull request: 1.31
  • Merged pull requests: 42
  • Bot issues: 0
  • Bot pull requests: 3
Past Year
  • Issues: 22
  • Pull requests: 14
  • Average time to close issues: 17 days
  • Average time to close pull requests: about 5 hours
  • Issue authors: 20
  • Pull request authors: 7
  • Average comments per issue: 1.05
  • Average comments per pull request: 0.79
  • Merged pull requests: 8
  • Bot issues: 0
  • Bot pull requests: 2
Top Authors
Issue Authors
  • cyw3 (17)
  • terryyin (6)
  • cg122 (5)
  • rakhimov (4)
  • cmius (3)
  • huornlmj (3)
  • MichaelBMiner (2)
  • yql70 (2)
  • mitchgrout (2)
  • mosesliao (2)
  • dhylands (2)
  • trouvant (2)
  • ishepard (2)
  • MarcW1g (2)
  • hgn (2)
Pull Request Authors
  • jdehaan (5)
  • Djaro08 (4)
  • krstf1 (4)
  • w31t1 (3)
  • jostrzol (3)
  • dependabot[bot] (3)
  • cyw3 (3)
  • dutchedge (3)
  • lijingda (2)
  • Lexxxzy (2)
  • riku311 (2)
  • jmal0 (2)
  • stkw0 (2)
  • salman-javed-nz (2)
  • ReallyLiri (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (3) javascript (2)

Packages

  • Total packages: 3
  • Total downloads:
    • homebrew 79 last-month
    • pypi 346,032 last-month
  • Total docker downloads: 653,293
  • Total dependent packages: 19
    (may contain duplicates)
  • Total dependent repositories: 188
    (may contain duplicates)
  • Total versions: 128
  • Total maintainers: 1
pypi.org: lizard

A code analyzer without caring the C/C++ header files. It works with Java, C/C++, JavaScript, Python, Ruby, Swift, Objective C. Metrics includes cyclomatic complexity number etc.

  • Versions: 115
  • Dependent Packages: 19
  • Dependent Repositories: 187
  • Downloads: 346,032 Last month
  • Docker Downloads: 653,293
Rankings
Downloads: 0.5%
Dependent packages count: 0.7%
Docker downloads count: 0.8%
Dependent repos count: 1.1%
Average: 1.4%
Stargazers count: 1.7%
Forks count: 3.4%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: lizard
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 1
Rankings
Stargazers count: 10.3%
Forks count: 11.9%
Dependent repos count: 24.4%
Average: 24.5%
Dependent packages count: 51.6%
Last synced: 6 months ago
formulae.brew.sh: lizard-analyzer

Extensible Cyclomatic Complexity Analyzer

  • Versions: 12
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 79 Last month
Rankings
Dependent packages count: 19.0%
Downloads: 33.7%
Average: 34.5%
Dependent repos count: 50.7%
Last synced: 6 months ago

Dependencies

.github/workflows/python-app.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
bower.json bower
  • angular 1.2.x
  • angular-animate ~1.2.x
  • angular-mocks ~1.2.x
  • angular-resource ~1.2.x
  • angular-route ~1.2.x
  • bootstrap ~3.1.1
  • jquery 1.10.2
website/static/bower/angular-animate/bower.json bower
  • angular 1.2.18
website/static/bower/angular-mocks/bower.json bower
  • angular 1.2.18
website/static/bower/angular-resource/bower.json bower
  • angular 1.2.18
website/static/bower/angular-route/bower.json bower
  • angular 1.2.18
website/static/bower/bootstrap/bower.json bower
  • jquery >= 1.9.0
website/static/bower/bootstrap/package.json npm
  • btoa ~1.1.1 development
  • canonical-json ~0.0.3 development
  • grunt ~0.4.2 development
  • grunt-banner ~0.2.0 development
  • grunt-contrib-clean ~0.5.0 development
  • grunt-contrib-concat ~0.3.0 development
  • grunt-contrib-connect ~0.6.0 development
  • grunt-contrib-copy ~0.5.0 development
  • grunt-contrib-csslint ~0.2.0 development
  • grunt-contrib-cssmin ~0.7.0 development
  • grunt-contrib-jade ~0.9.1 development
  • grunt-contrib-jshint ~0.8.0 development
  • grunt-contrib-less ~0.9.0 development
  • grunt-contrib-qunit ~0.4.0 development
  • grunt-contrib-uglify ~0.3.0 development
  • grunt-contrib-watch ~0.5.3 development
  • grunt-csscomb ~2.0.1 development
  • grunt-exec 0.4.3 development
  • grunt-html-validation ~0.1.13 development
  • grunt-jekyll ~0.4.1 development
  • grunt-jscs-checker ~0.3.0 development
  • grunt-saucelabs ~5.0.0 development
  • grunt-sed ~0.1.1 development
  • load-grunt-tasks ~0.3.0 development
  • markdown ~0.5.0 development
website/static/bower/jquery/package.json npm
  • archiver ~0.4.2 development
  • grunt 0.4.1 development
  • grunt-compare-size ~0.4.0 development
  • grunt-contrib-jshint 0.3.0 development
  • grunt-contrib-uglify 0.2.0 development
  • grunt-contrib-watch 0.3.1 development
  • grunt-git-authors 1.2.0 development
  • grunt-update-submodules 0.2.0 development
  • gzip-js 0.3.1 development
  • testswarm ~1.1.0 development
website/static/bower/jquery/composer.json packagist
  • robloach/component-installer *
dev_requirements.txt pypi
  • coverage * development
  • jinja2 * development
  • mock * development
  • nose * development
  • pycodestyle * development
  • pygments * development
  • pylint * development
  • pytest * development
  • twine * development
  • wheel * development
website/static/bower/bootstrap/test-infra/requirements.txt pypi
  • boto ==2.20.0 test