Skip to content

Commit 3a55663

Browse files
authored
fix: Fix too-long-variable-name throwing exception on Set X Variable without arguments (#1675)
1 parent 1e61415 commit 3a55663

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/robocop/linter/rules/lengths.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,13 @@ def visit_KeywordCall(self, node: KeywordCall) -> None: # noqa: N802
985985
return
986986
for variable in node.get_tokens(Token.ASSIGN):
987987
self.add_variable_to_scope(variable, strip_equals_from_assignment(variable.value))
988-
if normalize_robot_name(node.keyword) in self.set_variable_keywords: # Only check args of 'Set ... Variable'
989-
argument = node.get_token(Token.ARGUMENT)
990-
if argument.value.startswith(tuple(self.var_identifiers + "\\")): # Otherwise this is invalid RF syntax
991-
self.add_variable_to_scope(argument)
988+
# Only check args of 'Set ... Variable' and check for invalid RF syntax
989+
if (
990+
normalize_robot_name(node.keyword) in self.set_variable_keywords
991+
and (argument := node.get_token(Token.ARGUMENT))
992+
and argument.value.startswith(tuple(self.var_identifiers + "\\"))
993+
):
994+
self.add_variable_to_scope(argument)
992995

993996
def visit_Var(self, node: Statement) -> None: # noqa: N802
994997
if variable := node.get_token(Token.VARIABLE):

tests/linter/rules/lengths/too_long_variable_name/test.robot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ Keyword With ${short_embedded_argument_name} And ${embedded_argument_name_that_i
113113
Keyword ${embedded_just_shy_of_max_len_contains:pattern} And ${embedded_name_that_is_too_long_that_contains:pattern} # 44
114114
Log ${embedded_just_shy_of_max_len_contains}
115115

116+
Test Invalid Syntax
117+
Set Suite Variable # no argument

0 commit comments

Comments
 (0)