Rules / unused-local
Unused local variable in a POU
A variable is declared in VAR but appears neither in the body nor in its actions and methods. It is leftover logic or a typo, with a different name used in the body.
Severity: Minor
Rule id: unused-local
Unused local variable
What the rule checks
A local variable is declared in VAR but never appears in the POU body or its actions or methods: a leftover from deleted logic, or a typo in the body (in which case a different variable is doing the work).
What it does to the plant
If it is a typo, the program reads and writes the wrong variable while the intended one stays at zero.
Example
PROGRAM ScaleVAR rRaw : REAL; rScaled : REAL; rOldScaled : REAL;END_VARrScaled := rRaw * 2.0;
PROGRAM ScaleVAR rRaw : REAL; rScaled : REAL;END_VARrScaled := rRaw * 2.0;
Both listings are run through the linter by an automated test: the rule fires on the first and stays silent on the second.
How to fix
- Remove the unused declaration.
- Or wire the variable into the logic if it was forgotten.
Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.
The same linter without uploading a file: command line and GitHub Action.
Related rules
2026-11-26