{"id":5301,"library":"lizard","title":"Lizard Code Analyzer","description":"Lizard is an extensible Cyclomatic Complexity Analyzer for multiple programming languages, including C/C++, Java, JavaScript, Python, Ruby, Swift, and Objective C. It calculates metrics such as cyclomatic complexity number (CCN), lines of code (NLOC), token count, and parameter count. Version 1.21.3 is currently active, with a regular release cadence addressing bug fixes and improvements.","status":"active","version":"1.21.3","language":"en","source_language":"en","source_url":"https://github.com/terryyin/lizard","tags":["code analysis","static analysis","complexity metrics","cyclomatic complexity","multi-language","code quality","development tools"],"install":[{"cmd":"pip install lizard","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required runtime for the library. Modern versions (1.x.x) typically require Python 3.8+.","package":"Python","optional":false}],"imports":[{"note":"The primary way to interact with the library programmatically is by importing the top-level `lizard` module.","symbol":"lizard","correct":"import lizard"}],"quickstart":{"code":"import lizard\nimport os\n\n# Create a dummy Python file for analysis\ncode_to_analyze = '''\ndef calculate_something(a, b):\n    if a > 0:\n        if b > 0:\n            return a + b\n        else:\n            return a - b\n    elif a < 0:\n        return b\n    else:\n        return 0\n\nclass MyClass:\n    def __init__(self, val):\n        self.val = val\n\n    def get_val(self):\n        return self.val\n'''\n\nfile_path = \"example_for_lizard.py\"\nwith open(file_path, \"w\") as f:\n    f.write(code_to_analyze)\n\n# Analyze the file\n# lizard.analyze_file returns a 'FileInformation' object\nfile_info = lizard.analyze_file(file_path)\n\nprint(f\"\\n--- Analysis for {file_info.filename} ---\")\nprint(f\"Total lines of code (NLOC): {file_info.nloc}\")\n\nfor func_info in file_info.function_list:\n    print(f\"\\n  Function: {func_info.name}\")\n    print(f\"    Cyclomatic Complexity (CCN): {func_info.cyclomatic_complexity}\")\n    print(f\"    NLOC: {func_info.nloc}\")\n    print(f\"    Parameter Count: {func_info.parameters}\")\n    print(f\"    Token Count: {func_info.token_count}\")\n\n# Clean up the dummy file\nos.remove(file_path)\n\n# Example of analyzing a string directly (requires a filename hint for language detection)\nstring_code = \"def simple_func():\\n    pass\"\nstring_info = lizard.analyze_source_code(\"temp.py\", string_code)\nprint(f\"\\n--- Analysis for string code (temp.py) ---\")\nfor func_info in string_info.function_list:\n    print(f\"  Function: {func_info.name}, CCN: {func_info.cyclomatic_complexity}\")\n","lang":"python","description":"This quickstart demonstrates how to use `lizard` to analyze a Python file programmatically. It creates a dummy Python file, analyzes it, and prints out key metrics for each function found. It also shows how to analyze a source code string directly."},"warnings":[{"fix":"Check the exit code in scripts and configure your CI/CD to handle warnings as desired (e.g., fail on warnings or ignore them if above a certain threshold using the `-i` option).","message":"When running `lizard` from the command line, the tool will exit with a non-zero status code if any warnings are generated (e.g., functions exceeding complexity thresholds). This is intended for CI/CD pipelines but might be unexpected if not accounted for.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always quote exclusion patterns, especially those containing wildcards, to ensure they are passed correctly to `lizard`.","message":"When using the `--exclude` option (or `-x`) for file exclusion patterns, ensure to wrap patterns with quotation marks (e.g., `-x \"./tests/*\"`) to prevent shell expansion issues.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your environment uses Python 3.8 or a newer compatible version (e.g., Python 3.10+ is typically recommended for new development).","message":"Older versions of `lizard` (e.g., 1.7.x and earlier) supported Python 2.6/2.7/3.x. However, recent versions (like 1.21.3) are built for Python 3.8 and newer. Attempting to install or run the latest `lizard` on older Python 3 versions or Python 2 will result in errors.","severity":"breaking","affected_versions":"From ~1.8.0 onwards (specifically 1.20.0+ requires Python 3.8+)."},{"fix":"Be aware of how preprocessor directives impact complexity. If specific functions are intentionally complex due to such constructs, consider using the `#lizard forgives` comment within or before the function to suppress warnings for it.","message":"In C/C++ code, preprocessor directives like `#if` will increase the cyclomatic complexity count by default. This might lead to higher complexity scores than expected if you are not aware of this behavior.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}