Skip to content

Commit

Permalink
fix: unused-variable with variables in [Setup], [Teardown] and [Timeo…
Browse files Browse the repository at this point in the history
…ut] (#1063)
  • Loading branch information
bhirsz authored Mar 21, 2024
1 parent dba5f1f commit dfad472
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
5 changes: 5 additions & 0 deletions docs/releasenotes/unreleased/fixes.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
unused-variable when the variable is used in a Test Setup (#1062)
------------------------------------------------------------------

I0920 ``unused-variable`` was incorrectly reported if the variable was declared in the ``*** Variables ***`` section
and used in ``[Setup]``, ``[Teardown]`` or ``[Timeout]``.
8 changes: 7 additions & 1 deletion robocop/checkers/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,13 @@ def visit_LibraryImport(self, node): # noqa

visit_SuiteSetup = (
visit_SuiteTeardown
) = visit_TestSetup = visit_TestTeardown = visit_ResourceImport = visit_VariablesImport = visit_LibraryImport
) = (
visit_TestSetup
) = (
visit_TestTeardown
) = (
visit_Setup
) = visit_Teardown = visit_Timeout = visit_ResourceImport = visit_VariablesImport = visit_LibraryImport

def visit_DefaultTags(self, node): # noqa
for token in node.get_tokens(Token.ARGUMENT):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
test.robot:14:5:14:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:18:15:18:22 [I] 0920 Variable '${var2}' is assigned but not used
test.robot:22:5:22:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:30:5:30:14 [I] 0920 Variable '${assign}' is assigned but not used
test.robot:41:12:41:18 [I] 0920 Variable '${var}' is assigned but not used
test.robot:67:12:67:23 [I] 0920 Variable '${category}' is assigned but not used
test.robot:115:5:115:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:118:5:118:14 [I] 0920 Variable '${assign}' is assigned but not used
test.robot:121:12:121:23 [I] 0920 Variable '${not_used}' is assigned but not used
test.robot:129:12:129:23 [I] 0920 Variable '${variable}' is assigned but not used
test.robot:15:5:15:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:19:15:19:22 [I] 0920 Variable '${var2}' is assigned but not used
test.robot:23:5:23:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:31:5:31:14 [I] 0920 Variable '${assign}' is assigned but not used
test.robot:42:12:42:18 [I] 0920 Variable '${var}' is assigned but not used
test.robot:68:12:68:23 [I] 0920 Variable '${category}' is assigned but not used
test.robot:116:5:116:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:119:5:119:14 [I] 0920 Variable '${assign}' is assigned but not used
test.robot:122:12:122:23 [I] 0920 Variable '${not_used}' is assigned but not used
test.robot:130:12:130:23 [I] 0920 Variable '${variable}' is assigned but not used
unused_section_vars.robot:21:1:21:19 [I] 0920 Variable '${GLOBAL_NOT_USED}' is assigned but not used
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
test.robot:14:5:14:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:18:15:18:22 [I] 0920 Variable '${var2}' is assigned but not used
test.robot:22:5:22:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:30:5:30:14 [I] 0920 Variable '${assign}' is assigned but not used
test.robot:41:12:41:18 [I] 0920 Variable '${var}' is assigned but not used
test.robot:67:12:67:23 [I] 0920 Variable '${category}' is assigned but not used
test.robot:115:5:115:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:118:5:118:14 [I] 0920 Variable '${assign}' is assigned but not used
test.robot:15:5:15:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:19:15:19:22 [I] 0920 Variable '${var2}' is assigned but not used
test.robot:23:5:23:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:31:5:31:14 [I] 0920 Variable '${assign}' is assigned but not used
test.robot:42:12:42:18 [I] 0920 Variable '${var}' is assigned but not used
test.robot:68:12:68:23 [I] 0920 Variable '${category}' is assigned but not used
test.robot:116:5:116:11 [I] 0920 Variable '${var}' is assigned but not used
test.robot:119:5:119:14 [I] 0920 Variable '${assign}' is assigned but not used
unused_section_vars.robot:21:1:21:19 [I] 0920 Variable '${GLOBAL_NOT_USED}' is assigned but not used
5 changes: 5 additions & 0 deletions tests/atest/rules/misc/unused_variable/test.robot
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*** Variables ***
${VARIABLE} value
${USED_IN_SETUP} value


*** Keywords ***
Expand Down Expand Up @@ -128,3 +129,7 @@ Unused With VAR
Keyword Call ${used_without_sign}
VAR ${variable} # missing value
VAR $variable # ignored for invalid variable name
Unused In Setup
[Setup] Keyword Setup ${used_in_setup}
Step

0 comments on commit dfad472

Please sign in to comment.