Rules / undeclared-variable
A variable is used but declared nowhere: the CODESYS 4 project will not build
A POU body uses a name that is declared neither in the POU nor among the project POUs and types. In a CODESYS 4 project this is a typo or a forgotten declaration, including a signal typed onto an LD contact. The rule reads the .fbsdev folder directly, before compilation.
Severity: Critical
Rule id: undeclared-variable
Undeclared variable
This rule only runs on CODESYS 4 projects (a .fbsdev folder): a CODESYS 3 export with an undeclared name cannot exist, because the project does not compile.
What the rule checks
A variable is used in a POU body but is declared neither in that POU nor among the project POUs and types. A CODESYS 3 export with such a name cannot exist, because the project does not compile. A CODESYS 4 project, though, is a folder of files under git, and an unbuilt change slips into the repository easily: a misspelled name, a forgotten declaration, an LD contact wired to a signal that does not exist. The rule runs on CODESYS 4 projects (.fbsdev) only. If the project contains objects whose format is not supported yet (for example, global variable lists), the check is skipped entirely to avoid false findings, and the report says so.
What it does to the plant
An unbuilt change reaches the repository, and the build fails later in someone else's pipeline or on site during commissioning.
Example
PROGRAM PLC_PRGVAR bPumpRun : BOOL; bPumpCmd : BOOL;END_VARbPumpRun := bPumCmd;
PROGRAM PLC_PRGVAR bPumpRun : BOOL; bPumpCmd : BOOL;END_VARbPumpRun := bPumpCmd;
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
- Check the spelling against the declaration: case does not matter, underscores and digits do.
- If the variable is needed, declare it in a VAR block of the POU with a type and a comment.
- Build the application with
c4-cli bootapp compilein CI before the check: the compiler confirms the finding with its own error.
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