# Static Code Analysis in CI/CD using Lizard

**URL:** <https://community.br-automation.com/t/static-code-analysis-in-ci-cd-using-lizard/8578>\
**Category:** How-To & Wikis\
**Created:** [October 3, 2025, 11:24am UTC](https://community.br-automation.com/t/static-code-analysis-in-ci-cd-using-lizard/8578 "2025-10-03T11:24:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wLahn](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/wlahn/32/8698_2.png) [@wLahn](https://community.br-automation.com/u/wLahn)\
**Post date:** [October 3, 2025, 11:24am UTC](https://community.br-automation.com/t/static-code-analysis-in-ci-cd-using-lizard/8578/1 "2025-10-03T11:24:17Z")

</div>

# Static Code Analysis in CI/CD for Structured Text

To raise the quality and maintainability of our B&R projects, we integrated **[Lizard](https://github.com/terryyin/lizard)**, a static code analysis tool, into our CI/CD pipeline.

We found it really useful for keeping our code maintainable, and thought it might be interesting for other developers here, who struggle with an ever growing code base.

Even though we are not affiliated with Lizard, we made some contributions for supporting Structured Text. This allowed us to apply it on our whole code base, which is on large parts written in ST.

## Why Static Analysis?

Unlike testing, static analysis inspects code without executing it. This means potential issues are caught early and automatically:

- Functions with **high cyclomatic complexity** (CCN) or **high nesting depth** (ND) are flagged before they become unmaintainable.

- **Duplicate code blocks** are detected, encouraging refactoring and reuse.

- Quality metrics are tracked consistently over time.

## Example Test Report

```auto
================================================
  NLOC CCN ND token PARAM length location
----------------------------------------------------
     35 12 6 120 3 50 src/MotionControl.st:func_MoveAxis()
     20 4 2 80 2 25 src/Sensor.st:func_CheckLimits()
================================================

```

- `CCN=12` → function has a high branching complexity, should be refactored.

- `ND=6` → deep nesting, code may be hard to follow and maintain.

- `CCN=4 / ND=2` → acceptable, no action needed.

## Integration in CI/CD

We already implemented a CI/CD pipeline, which basically executes the following steps if a developer commits some new code:

1. **Build & test:** Execute all Unit Tests and report failure.

2. **Code Linter** : Checks Spelling, formatting, etc.

3. **Static analysis with Lizard** : Report complexity and code duplicates.

This ensures immediate feedback for the developer and enforces at least a minimum of code quality.

## Looking for Insights

We would be interested to hear from your experiences with similar tools:

- Do you already use static code analysis in your PLC projects?

- Have you tried other tools that work well with Structured Text?

- Any lessons learned or best practices to share?

---

<div class="post-metadata">

**Author:** ![mreiter](https://avatars.discourse-cdn.com/v4/letter/m/FF8800/32.png) [@mreiter](https://community.br-automation.com/u/mreiter)\
**Post date:** [October 8, 2025, 6:31am UTC](https://community.br-automation.com/t/static-code-analysis-in-ci-cd-using-lizard/8578/2 "2025-10-08T06:31:36Z")

</div>

Very interesting.

Since you mentioned code linting. What tools do you you use for that purpose?

---

<div class="post-metadata">

**Author:** ![Patrick\_Schmitter](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/patrick_schmitter/32/489_2.png) [@Patrick\_Schmitter](https://community.br-automation.com/u/Patrick_Schmitter)\
**Post date:** [October 8, 2025, 11:33am UTC](https://community.br-automation.com/t/static-code-analysis-in-ci-cd-using-lizard/8578/3 "2025-10-08T11:33:25Z")

</div>

Hi Lukas

Thanks for sharing a used tool. For code formatting we are using [AStyle](https://astyle.sourceforge.net/) for code formatting and [CppCheck](https://cppcheck.sourceforge.io/) for static code analysis.  
Both integrated in our CI/CD process.

Cheers  
Patrick

---

<div class="post-metadata">

**Author:** ![wLahn](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/wlahn/32/8698_2.png) [@wLahn](https://community.br-automation.com/u/wLahn)\
**Post date:** [October 9, 2025, 2:18pm UTC](https://community.br-automation.com/t/static-code-analysis-in-ci-cd-using-lizard/8578/4 "2025-10-09T14:18:31Z")

</div>

Hi Martin,

depending on the project, we use cspell for grammar and pre-commit for handling file/line endings and trailing whitespaces, but also various self made stuff e. g. for sorting structures alphabetically, enforcing naming conventions and so on.

Also, for specific library functions where references are passed via `UDINT`, the correct address resolution via `&` is checked to avoid some pitfalls we encountered with this in the past.

---

<div class="post-metadata">

**Author:** ![wLahn](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/wlahn/32/8698_2.png) [@wLahn](https://community.br-automation.com/u/wLahn)\
**Post date:** [October 9, 2025, 2:24pm UTC](https://community.br-automation.com/t/static-code-analysis-in-ci-cd-using-lizard/8578/5 "2025-10-09T14:24:30Z")

</div>

Hi Patrick,

AStyle looks quite interesting!

I assume you got a codebase of mostly c then, or did you find it useful for structured text as well?

---

<div class="post-metadata">

**Author:** ![Patrick\_Schmitter](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/patrick_schmitter/32/489_2.png) [@Patrick\_Schmitter](https://community.br-automation.com/u/Patrick_Schmitter)\
**Post date:** [October 10, 2025, 6:56am UTC](https://community.br-automation.com/t/static-code-analysis-in-ci-cd-using-lizard/8578/6 "2025-10-10T06:56:57Z")

</div>

Hi Lukas

You assumed correct ;-).  
Our codebase is completely written in C so therefore i don’t know if the tool is suitable for a mixed or ST codebase you.

Cheers  
Patrick
