-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Description
The ReplaceWithVAR transformer silently corrupts Robot Framework code when converting Create Dictionary or Create List calls that contain inline comments (#). The comment marker gets orphaned, and the tokens after # become standalone lines that Robot Framework interprets as keyword calls.
This causes silent runtime failures — the transformed code is syntactically valid but semantically broken.
Versions
- robocop: 8.2.4 (also confirmed on 8.2.3)
- Robot Framework: 7.2
- Python: 3.13.7
- OS: Windows 11
Reproduction
Case 1: Create Dictionary with inline comment
Input (repro_dict.robot):
*** Test Cases ***
Example Dict
&{task_dict} Create Dictionary # Task/Subtask State=Task/Subtask Name Subtask Status=Subtask Name
Log &{task_dict}Command:
python -m robocop format --select ReplaceWithVAR repro_dict.robot
Actual output:
*** Test Cases ***
Example Dict
#
Task/Subtask State=Task/Subtask Name
Subtask Status=Subtask Name
VAR &{task_dict} &{EMPTY}
Log &{task_dict}Runtime error (robot --dryrun repro_dict.robot):
==============================================================================
Example Dict | FAIL |
Several failures occurred:
1) No keyword with name 'Task/Subtask State=Task/Subtask Name' found.
2) No keyword with name 'Subtask Status=Subtask Name' found.
==============================================================================
Expected: The # and everything after it should remain as a single comment line (or be dropped entirely), and VAR &{task_dict} &{EMPTY} should be the only executable line. The key=value pairs after # should never become standalone executable lines.
Case 2: Create List with inline comment
Input (repro_list.robot):
*** Test Cases ***
Example List
@{items} Create List # Asset_REST (AssetRESTAPIData) Project_Site_Unit
Log @{items}Command:
python -m robocop format --select ReplaceWithVAR repro_list.robot
Actual output:
*** Test Cases ***
Example List
#
Asset_REST (AssetRESTAPIData)
Project_Site_Unit
VAR @{items} @{EMPTY}
Log @{items}Runtime error (robot --dryrun repro_list.robot):
==============================================================================
Example List | FAIL |
Several failures occurred:
1) No keyword with name 'Asset_REST (AssetRESTAPIData)' found.
2) No keyword with name 'Project_Site_Unit' found.
==============================================================================
Impact
This is a silent code corruption bug. The transformer produces syntactically valid .robot files that fail at runtime with misleading keyword-not-found errors. In our case it broke 12 test files across a large test suite after running robocop format, and the root cause was not obvious from the error messages alone.
Workaround
We manually re-merged the orphaned comment content back onto the # line after formatting. No robocop configuration option prevents this.