diff --git a/docs/rules_list.md b/docs/rules_list.md index 394759710..77a47a269 100644 --- a/docs/rules_list.md +++ b/docs/rules_list.md @@ -13351,29 +13351,19 @@ Robot Framework 7.3 introduced type conversion for variables. This rule enforces that variables in the ``*** Variables ***`` section have explicit type annotations for better code clarity and automatic type conversion. -This rule also checks ``VAR`` statements and assignment expressions -(``${var} = Keyword``). +Variables defined in keywords and tests are checked by the separate +``missing-keyword-variable-type`` and ``missing-test-variable-type`` rules. Incorrect code example (when rule is enabled): *** Variables *** ${NUMBER} 42 - *** Keywords *** - Example - VAR ${local} value - ${result} = Some Keyword - Correct code: *** Variables *** ${NUMBER: int} 42 - *** Keywords *** - Example - VAR ${local: str} value - ${result: list} = Some Keyword - This rule is disabled by default. **Parameters**: @@ -13595,3 +13585,135 @@ The VAR syntax needs to be used instead: "set-keyword-with-type.severity=E" ] ``` + +--- + +### ANN05: missing-keyword-variable-type + +> Rule is disabled by default. Enable it by using ``--select missing-keyword-variable-type`` option. + +Added: `v9.5.0` + +Supported RF version `>=7.3` + +Fix availability: There is no automatic fix. + +**Message**: + +`Variable '{variable_name}' is missing type annotation` + +**Documentation**: + +Keyword variable without type annotation. + +Robot Framework 7.3 introduced type conversion for variables. This rule +enforces that variables created inside keywords with ``VAR`` statements and +assignment expressions (``${var} = Keyword``) have explicit type annotations +for better code clarity and automatic type conversion. + +Incorrect code example (when rule is enabled): + + *** Keywords *** + Example + VAR ${local} value + ${result} = Some Keyword + +Correct code: + + *** Keywords *** + Example + VAR ${local: str} value + ${result: list} = Some Keyword + +This rule is disabled by default. + +**Parameters**: + +??? example "severity" + + Rule severity (e = error, w = warning, i = info) + + **Default value:** I + + **Type:** severity + + === ":octicons-command-palette-24: cli" + + ``` bash + robocop check --configure missing-keyword-variable-type.severity=I + ``` + + === ":material-file-cog-outline: toml" + + ``` toml + [tool.robocop.lint] + configure = [ + "missing-keyword-variable-type.severity=I" + ] + ``` + +--- + +### ANN06: missing-test-variable-type + +> Rule is disabled by default. Enable it by using ``--select missing-test-variable-type`` option. + +Added: `v9.5.0` + +Supported RF version `>=7.3` + +Fix availability: There is no automatic fix. + +**Message**: + +`Variable '{variable_name}' is missing type annotation` + +**Documentation**: + +Test variable without type annotation. + +Robot Framework 7.3 introduced type conversion for variables. This rule +enforces that variables created inside tests or tasks with ``VAR`` statements and +assignment expressions (``${var} = Keyword``) have explicit type annotations +for better code clarity and automatic type conversion. + +Incorrect code example (when rule is enabled): + + *** Test Cases *** + Example + VAR ${local} value + ${result} = Some Keyword + +Correct code: + + *** Test Cases *** + Example + VAR ${local: str} value + ${result: list} = Some Keyword + +This rule is disabled by default. + +**Parameters**: + +??? example "severity" + + Rule severity (e = error, w = warning, i = info) + + **Default value:** I + + **Type:** severity + + === ":octicons-command-palette-24: cli" + + ``` bash + robocop check --configure missing-test-variable-type.severity=I + ``` + + === ":material-file-cog-outline: toml" + + ``` toml + [tool.robocop.lint] + configure = [ + "missing-test-variable-type.severity=I" + ] + ``` diff --git a/src/robocop/linter/checkers/variable_statements.py b/src/robocop/linter/checkers/variable_statements.py index fc8e8f175..e6646c89e 100644 --- a/src/robocop/linter/checkers/variable_statements.py +++ b/src/robocop/linter/checkers/variable_statements.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from robot.parsing.model import File - from robot.parsing.model.blocks import For, KeywordSection, VariableSection + from robot.parsing.model.blocks import For, KeywordSection, TestCaseSection, VariableSection from robot.parsing.model.statements import Arguments, KeywordCall, Var, Variable @@ -24,6 +24,8 @@ class VariablesChecker(VisitorChecker): no_test_variable: variables.NoTestVariableRule set_keyword_with_type: typing.SetKeywordWithTypeRule missing_section_variable_type: typing.MissingSectionVariableTypeRule + missing_keyword_variable_type: typing.MissingKeywordVariableTypeRule + missing_test_variable_type: typing.MissingTestVariableTypeRule missing_argument_type: typing.MissingArgumentTypeRule missing_for_loop_variable_type: typing.MissingForLoopVariableTypeRule inconsistent_assignment: misc.InconsistentAssignmentRule @@ -41,10 +43,14 @@ def __init__(self) -> None: self.keyword_expected_sign_type: str | None = None self.variables_expected_sign_type: str | None = None self.check_empty_variable = True + self.missing_body_variable_type: ( + typing.MissingKeywordVariableTypeRule | typing.MissingTestVariableTypeRule | None + ) = None super().__init__() def visit_File(self, node: File) -> None: # noqa: N802 self.check_empty_variable = True + self.missing_body_variable_type = None self.detect_assignment_sign(node) self.generic_visit(node) @@ -70,12 +76,26 @@ def visit_VariableSection(self, node: VariableSection) -> None: # noqa: N802 self.check_empty_variable = True def visit_KeywordSection(self, node: KeywordSection) -> None: # noqa: N802 + self.visit_body_section(node, self.missing_keyword_variable_type) + + def visit_TestCaseSection(self, node: TestCaseSection) -> None: # noqa: N802 + self.visit_body_section(node, self.missing_test_variable_type) + + def visit_body_section( + self, + node: KeywordSection | TestCaseSection, + missing_type_rule: typing.MissingKeywordVariableTypeRule | typing.MissingTestVariableTypeRule, + ) -> None: # ``empty-variable`` is only reported here when the VAR syntax is one of its configured sources self.check_empty_variable = "var" in self.empty_variable.variable_source + self.missing_body_variable_type = missing_type_rule self.generic_visit(node) self.check_empty_variable = True + self.missing_body_variable_type = None - visit_TestCaseSection = visit_KeywordSection # noqa: N815 + def check_body_variable_type(self, node: Var | KeywordCall, token: Token) -> None: + if self.missing_body_variable_type is not None: + self.missing_body_variable_type.check(node, token) def visit_Variable(self, node: Variable) -> None: # noqa: N802 if self.check_empty_variable: @@ -93,7 +113,7 @@ def visit_Var(self, node: Var) -> None: # noqa: N802 return variable = node.get_token(Token.VARIABLE) if variable: - self.missing_section_variable_type.check(node, variable) + self.check_body_variable_type(node, variable) self.check_var_assignment_sign(variable) def check_var_assignment_sign(self, variable: Token) -> None: @@ -119,7 +139,7 @@ def check_var_scope(self, node: Var) -> None: def visit_KeywordCall(self, node: KeywordCall) -> None: # noqa: N802 self.check_assignment_sign(node) for token in node.get_tokens(Token.ASSIGN): - self.missing_section_variable_type.check(node, token) + self.check_body_variable_type(node, token) self.check_set_variable_keyword(node) def check_assignment_sign(self, node: KeywordCall) -> None: diff --git a/src/robocop/linter/rules/typing.py b/src/robocop/linter/rules/typing.py index af12ecee0..faebae2e4 100644 --- a/src/robocop/linter/rules/typing.py +++ b/src/robocop/linter/rules/typing.py @@ -42,6 +42,20 @@ def should_report_missing_type(var_name: str) -> bool: return bool(var_match.base) and not has_type_annotation(var_match.base) and not is_ignore_variable(var_match.base) +def report_missing_variable_type(rule: Rule, node: Node, token: Token) -> None: + """Report ``rule`` if the variable in ``token`` is missing type annotation.""" + if not rule.enabled or not should_report_missing_type(token.value): + return + var_match = search_variable(token.value, ignore_errors=True) + rule.report( + variable_name=var_match.match, + node=node, + lineno=token.lineno, + col=token.col_offset + 1, + end_col=token.end_col_offset + 1, + ) + + class MissingSectionVariableTypeRule(Rule): """ Section variable without type annotation. @@ -50,14 +64,50 @@ class MissingSectionVariableTypeRule(Rule): enforces that variables in the ``*** Variables ***`` section have explicit type annotations for better code clarity and automatic type conversion. - This rule also checks ``VAR`` statements and assignment expressions - (``${var} = Keyword``). + Variables defined in keywords and tests are checked by the separate + ``missing-keyword-variable-type`` and ``missing-test-variable-type`` rules. Incorrect code example (when rule is enabled): *** Variables *** ${NUMBER} 42 + Correct code: + + *** Variables *** + ${NUMBER: int} 42 + + This rule is disabled by default. + + """ + + name = "missing-section-variable-type" + rule_id = "ANN01" + message = "Variable '{variable_name}' is missing type annotation" + severity = RuleSeverity.INFO + version = ">=7.3" + enabled = False + added_in_version = "7.1.0" + sonar_qube_attrs = sonar_qube.SonarQubeAttributes( + clean_code=sonar_qube.CleanCodeAttribute.CLEAR, issue_type=sonar_qube.SonarQubeIssueType.CODE_SMELL + ) + + def check(self, node: Node, token: Token) -> None: + """Check a variable name token from the variables section.""" + report_missing_variable_type(self, node, token) + + +class MissingKeywordVariableTypeRule(Rule): + """ + Keyword variable without type annotation. + + Robot Framework 7.3 introduced type conversion for variables. This rule + enforces that variables created inside keywords with ``VAR`` statements and + assignment expressions (``${var} = Keyword``) have explicit type annotations + for better code clarity and automatic type conversion. + + Incorrect code example (when rule is enabled): + *** Keywords *** Example VAR ${local} value @@ -65,9 +115,6 @@ class MissingSectionVariableTypeRule(Rule): Correct code: - *** Variables *** - ${NUMBER: int} 42 - *** Keywords *** Example VAR ${local: str} value @@ -77,29 +124,63 @@ class MissingSectionVariableTypeRule(Rule): """ - name = "missing-section-variable-type" - rule_id = "ANN01" + name = "missing-keyword-variable-type" + rule_id = "ANN05" message = "Variable '{variable_name}' is missing type annotation" severity = RuleSeverity.INFO version = ">=7.3" enabled = False - added_in_version = "7.1.0" + added_in_version = "9.5.0" sonar_qube_attrs = sonar_qube.SonarQubeAttributes( clean_code=sonar_qube.CleanCodeAttribute.CLEAR, issue_type=sonar_qube.SonarQubeIssueType.CODE_SMELL ) def check(self, node: Node, token: Token) -> None: - """Check a variable name token from the variables section, a ``VAR`` statement or an assignment.""" - if not self.enabled or not should_report_missing_type(token.value): - return - var_match = search_variable(token.value, ignore_errors=True) - self.report( - variable_name=var_match.match, - node=node, - lineno=token.lineno, - col=token.col_offset + 1, - end_col=token.end_col_offset + 1, - ) + """Check a variable name token from a ``VAR`` statement or an assignment inside a keyword.""" + report_missing_variable_type(self, node, token) + + +class MissingTestVariableTypeRule(Rule): + """ + Test variable without type annotation. + + Robot Framework 7.3 introduced type conversion for variables. This rule + enforces that variables created inside tests or tasks with ``VAR`` statements and + assignment expressions (``${var} = Keyword``) have explicit type annotations + for better code clarity and automatic type conversion. + + Incorrect code example (when rule is enabled): + + *** Test Cases *** + Example + VAR ${local} value + ${result} = Some Keyword + + Correct code: + + *** Test Cases *** + Example + VAR ${local: str} value + ${result: list} = Some Keyword + + This rule is disabled by default. + + """ + + name = "missing-test-variable-type" + rule_id = "ANN06" + message = "Variable '{variable_name}' is missing type annotation" + severity = RuleSeverity.INFO + version = ">=7.3" + enabled = False + added_in_version = "9.5.0" + sonar_qube_attrs = sonar_qube.SonarQubeAttributes( + clean_code=sonar_qube.CleanCodeAttribute.CLEAR, issue_type=sonar_qube.SonarQubeIssueType.CODE_SMELL + ) + + def check(self, node: Node, token: Token) -> None: + """Check a variable name token from a ``VAR`` statement or an assignment inside a test or task.""" + report_missing_variable_type(self, node, token) class MissingArgumentTypeRule(Rule): diff --git a/tests/linter/rules/typing/missing_keyword_variable_type/__init__.py b/tests/linter/rules/typing/missing_keyword_variable_type/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/linter/rules/typing/missing_keyword_variable_type/expected_extended.txt b/tests/linter/rules/typing/missing_keyword_variable_type/expected_extended.txt new file mode 100644 index 000000000..356f2e64b --- /dev/null +++ b/tests/linter/rules/typing/missing_keyword_variable_type/expected_extended.txt @@ -0,0 +1,50 @@ +test.robot:28:12 ANN05 Variable '${local}' is missing type annotation + | + 26 | *** Keywords *** + 27 | Keyword With VAR + 28 | VAR ${local} value + | ^^^^^^^^ ANN05 + 29 | VAR ${typed_local: str} value + 30 | VAR ${_ignored} value + | + +test.robot:35:12 ANN05 Variable '${multiline_var}' is missing type annotation + | + 33 | Keyword With Multiline VAR + 34 | VAR + 35 | ... ${multiline_var} + | ^^^^^^^^^^^^^^^^ ANN05 + 36 | ... value + 37 | VAR + | + +test.robot:43:5 ANN05 Variable '${result}' is missing type annotation + | + 41 | + 42 | Keyword With Assignment + 43 | ${result} = Set Variable value + | ^^^^^^^^^^^ ANN05 + 44 | ${typed_result: list} = Create List one two + 45 | ${_ignored} = Set Variable value + | + +test.robot:50:16 ANN05 Variable '${in_if}' is missing type annotation + | + 48 | Keyword With Nested Blocks + 49 | IF $condition + 50 | VAR ${in_if} value + | ^^^^^^^^ ANN05 + 51 | END + 52 | FOR ${item: str} IN a b + | + +test.robot:53:9 ANN05 Variable '${in_for}' is missing type annotation + | + 51 | END + 52 | FOR ${item: str} IN a b + 53 | ${in_for} = Set Variable ${item} + | ^^^^^^^^^^^ ANN05 + 54 | END + | + +Found 5 issues. diff --git a/tests/linter/rules/typing/missing_keyword_variable_type/expected_output.txt b/tests/linter/rules/typing/missing_keyword_variable_type/expected_output.txt new file mode 100644 index 000000000..94a75471a --- /dev/null +++ b/tests/linter/rules/typing/missing_keyword_variable_type/expected_output.txt @@ -0,0 +1,7 @@ +test.robot:28:12 [I] ANN05 Variable '${local}' is missing type annotation +test.robot:35:12 [I] ANN05 Variable '${multiline_var}' is missing type annotation +test.robot:43:5 [I] ANN05 Variable '${result}' is missing type annotation +test.robot:50:16 [I] ANN05 Variable '${in_if}' is missing type annotation +test.robot:53:9 [I] ANN05 Variable '${in_for}' is missing type annotation + +Found 5 issues. \ No newline at end of file diff --git a/tests/linter/rules/typing/missing_keyword_variable_type/tasks.robot b/tests/linter/rules/typing/missing_keyword_variable_type/tasks.robot new file mode 100644 index 000000000..c2e54cdd1 --- /dev/null +++ b/tests/linter/rules/typing/missing_keyword_variable_type/tasks.robot @@ -0,0 +1,5 @@ +*** Tasks *** +Task With VAR + VAR ${task_local} value + ${task_result} = Set Variable value + VAR ${typed_task_local: str} value diff --git a/tests/linter/rules/typing/missing_keyword_variable_type/test.robot b/tests/linter/rules/typing/missing_keyword_variable_type/test.robot new file mode 100644 index 000000000..647bc20a0 --- /dev/null +++ b/tests/linter/rules/typing/missing_keyword_variable_type/test.robot @@ -0,0 +1,54 @@ +*** Variables *** +${SECTION} value + + +*** Test Cases *** +Test With VAR + VAR ${test_local} value + VAR ${typed_test_local: str} value + VAR ${_ignored} value + Log ${test_local} ${typed_test_local} + +Test With Multiline VAR + VAR + ... ${test_multiline} + ... value + Log ${test_multiline} + +Test With Assignment + ${test_result} = Set Variable value + ${first} ${second: int} Set Variable 1 2 + ${typed_result: list} = Create List one two + ${_ignored} = Set Variable value + Log ${test_result} + + +*** Keywords *** +Keyword With VAR + VAR ${local} value + VAR ${typed_local: str} value + VAR ${_ignored} value + Log ${local} ${typed_local} + +Keyword With Multiline VAR + VAR + ... ${multiline_var} + ... value + VAR + ... ${typed_multiline: str} + ... value + Log ${multiline_var} ${typed_multiline} + +Keyword With Assignment + ${result} = Set Variable value + ${typed_result: list} = Create List one two + ${_ignored} = Set Variable value + Log ${result} ${typed_result} + +Keyword With Nested Blocks + IF $condition + VAR ${in_if} value + END + FOR ${item: str} IN a b + ${in_for} = Set Variable ${item} + END diff --git a/tests/linter/rules/typing/missing_keyword_variable_type/test_rule.py b/tests/linter/rules/typing/missing_keyword_variable_type/test_rule.py new file mode 100644 index 000000000..5e5a84666 --- /dev/null +++ b/tests/linter/rules/typing/missing_keyword_variable_type/test_rule.py @@ -0,0 +1,18 @@ +from tests.linter.utils import RuleAcceptance + + +class TestRuleAcceptance(RuleAcceptance): + def test_rule(self): + self.check_rule( + src_files=["test.robot", "tasks.robot"], + expected_file="expected_output.txt", + test_on_version=">=7.3", + ) + + def test_extended(self): + self.check_rule( + src_files=["test.robot", "tasks.robot"], + expected_file="expected_extended.txt", + output_format="extended", + test_on_version=">=7.3", + ) diff --git a/tests/linter/rules/typing/missing_section_variable_type/expected_extended.txt b/tests/linter/rules/typing/missing_section_variable_type/expected_extended.txt index 536fc1def..1eb229f74 100644 --- a/tests/linter/rules/typing/missing_section_variable_type/expected_extended.txt +++ b/tests/linter/rules/typing/missing_section_variable_type/expected_extended.txt @@ -53,34 +53,4 @@ test.robot:28:1 ANN01 Variable '${MULTILINE}' is missing type annotation 30 | ... line2 | -test.robot:35:12 ANN01 Variable '${local}' is missing type annotation - | - 33 | *** Keywords *** - 34 | Keyword With VAR - 35 | VAR ${local} value - | ^^^^^^^^ ANN01 - 36 | VAR ${typed_local: str} value - 37 | VAR ${_ignored} value - | - -test.robot:42:12 ANN01 Variable '${multiline_var}' is missing type annotation - | - 40 | Keyword With Multiline VAR - 41 | VAR - 42 | ... ${multiline_var} - | ^^^^^^^^^^^^^^^^ ANN01 - 43 | ... value - 44 | VAR - | - -test.robot:50:5 ANN01 Variable '${result}' is missing type annotation - | - 48 | - 49 | Keyword With Assignment - 50 | ${result} = Set Variable value - | ^^^^^^^^^^^ ANN01 - 51 | ${typed_result: list} = Create List one two - 52 | ${_ignored} = Set Variable value - | - -Found 9 issues. \ No newline at end of file +Found 6 issues. diff --git a/tests/linter/rules/typing/missing_section_variable_type/expected_output.txt b/tests/linter/rules/typing/missing_section_variable_type/expected_output.txt index 2e7e445f2..a9ddf5cf4 100644 --- a/tests/linter/rules/typing/missing_section_variable_type/expected_output.txt +++ b/tests/linter/rules/typing/missing_section_variable_type/expected_output.txt @@ -4,8 +4,5 @@ test.robot:5:1 [I] ANN01 Variable '&{DICT}' is missing type annotation test.robot:13:1 [I] ANN01 Variable '${NO_SPACE:pattern}' is missing type annotation test.robot:20:1 [I] ANN01 Variable '${var}' is missing type annotation test.robot:28:1 [I] ANN01 Variable '${MULTILINE}' is missing type annotation -test.robot:35:12 [I] ANN01 Variable '${local}' is missing type annotation -test.robot:42:12 [I] ANN01 Variable '${multiline_var}' is missing type annotation -test.robot:50:5 [I] ANN01 Variable '${result}' is missing type annotation -Found 9 issues. \ No newline at end of file +Found 6 issues. \ No newline at end of file diff --git a/tests/linter/rules/typing/missing_test_variable_type/__init__.py b/tests/linter/rules/typing/missing_test_variable_type/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/linter/rules/typing/missing_test_variable_type/expected_extended.txt b/tests/linter/rules/typing/missing_test_variable_type/expected_extended.txt new file mode 100644 index 000000000..4f1e2d467 --- /dev/null +++ b/tests/linter/rules/typing/missing_test_variable_type/expected_extended.txt @@ -0,0 +1,60 @@ +test.robot:7:12 ANN06 Variable '${test_local}' is missing type annotation + | + 5 | *** Test Cases *** + 6 | Test With VAR + 7 | VAR ${test_local} value + | ^^^^^^^^^^^^^ ANN06 + 8 | VAR ${typed_test_local: str} value + 9 | VAR ${_ignored} value + | + +test.robot:14:12 ANN06 Variable '${test_multiline}' is missing type annotation + | + 12 | Test With Multiline VAR + 13 | VAR + 14 | ... ${test_multiline} + | ^^^^^^^^^^^^^^^^^ ANN06 + 15 | ... value + 16 | Log ${test_multiline} + | + +test.robot:19:5 ANN06 Variable '${test_result}' is missing type annotation + | + 17 | + 18 | Test With Assignment + 19 | ${test_result} = Set Variable value + | ^^^^^^^^^^^^^^^^ ANN06 + 20 | ${first} ${second: int} Set Variable 1 2 + 21 | ${typed_result: list} = Create List one two + | + +test.robot:20:5 ANN06 Variable '${first}' is missing type annotation + | + 18 | Test With Assignment + 19 | ${test_result} = Set Variable value + 20 | ${first} ${second: int} Set Variable 1 2 + | ^^^^^^^^ ANN06 + 21 | ${typed_result: list} = Create List one two + 22 | ${_ignored} = Set Variable value + | + +tasks.robot:3:12 ANN06 Variable '${task_local}' is missing type annotation + | + 1 | *** Tasks *** + 2 | Task With VAR + 3 | VAR ${task_local} value + | ^^^^^^^^^^^^^ ANN06 + 4 | ${task_result} = Set Variable value + 5 | VAR ${typed_task_local: str} value + | + +tasks.robot:4:5 ANN06 Variable '${task_result}' is missing type annotation + | + 2 | Task With VAR + 3 | VAR ${task_local} value + 4 | ${task_result} = Set Variable value + | ^^^^^^^^^^^^^^^^ ANN06 + 5 | VAR ${typed_task_local: str} value + | + +Found 6 issues. diff --git a/tests/linter/rules/typing/missing_test_variable_type/expected_output.txt b/tests/linter/rules/typing/missing_test_variable_type/expected_output.txt new file mode 100644 index 000000000..56970f8d0 --- /dev/null +++ b/tests/linter/rules/typing/missing_test_variable_type/expected_output.txt @@ -0,0 +1,8 @@ +tasks.robot:3:12 [I] ANN06 Variable '${task_local}' is missing type annotation +tasks.robot:4:5 [I] ANN06 Variable '${task_result}' is missing type annotation +test.robot:14:12 [I] ANN06 Variable '${test_multiline}' is missing type annotation +test.robot:19:5 [I] ANN06 Variable '${test_result}' is missing type annotation +test.robot:20:5 [I] ANN06 Variable '${first}' is missing type annotation +test.robot:7:12 [I] ANN06 Variable '${test_local}' is missing type annotation + +Found 6 issues. \ No newline at end of file diff --git a/tests/linter/rules/typing/missing_test_variable_type/tasks.robot b/tests/linter/rules/typing/missing_test_variable_type/tasks.robot new file mode 100644 index 000000000..c2e54cdd1 --- /dev/null +++ b/tests/linter/rules/typing/missing_test_variable_type/tasks.robot @@ -0,0 +1,5 @@ +*** Tasks *** +Task With VAR + VAR ${task_local} value + ${task_result} = Set Variable value + VAR ${typed_task_local: str} value diff --git a/tests/linter/rules/typing/missing_test_variable_type/test.robot b/tests/linter/rules/typing/missing_test_variable_type/test.robot new file mode 100644 index 000000000..647bc20a0 --- /dev/null +++ b/tests/linter/rules/typing/missing_test_variable_type/test.robot @@ -0,0 +1,54 @@ +*** Variables *** +${SECTION} value + + +*** Test Cases *** +Test With VAR + VAR ${test_local} value + VAR ${typed_test_local: str} value + VAR ${_ignored} value + Log ${test_local} ${typed_test_local} + +Test With Multiline VAR + VAR + ... ${test_multiline} + ... value + Log ${test_multiline} + +Test With Assignment + ${test_result} = Set Variable value + ${first} ${second: int} Set Variable 1 2 + ${typed_result: list} = Create List one two + ${_ignored} = Set Variable value + Log ${test_result} + + +*** Keywords *** +Keyword With VAR + VAR ${local} value + VAR ${typed_local: str} value + VAR ${_ignored} value + Log ${local} ${typed_local} + +Keyword With Multiline VAR + VAR + ... ${multiline_var} + ... value + VAR + ... ${typed_multiline: str} + ... value + Log ${multiline_var} ${typed_multiline} + +Keyword With Assignment + ${result} = Set Variable value + ${typed_result: list} = Create List one two + ${_ignored} = Set Variable value + Log ${result} ${typed_result} + +Keyword With Nested Blocks + IF $condition + VAR ${in_if} value + END + FOR ${item: str} IN a b + ${in_for} = Set Variable ${item} + END diff --git a/tests/linter/rules/typing/missing_test_variable_type/test_rule.py b/tests/linter/rules/typing/missing_test_variable_type/test_rule.py new file mode 100644 index 000000000..5e5a84666 --- /dev/null +++ b/tests/linter/rules/typing/missing_test_variable_type/test_rule.py @@ -0,0 +1,18 @@ +from tests.linter.utils import RuleAcceptance + + +class TestRuleAcceptance(RuleAcceptance): + def test_rule(self): + self.check_rule( + src_files=["test.robot", "tasks.robot"], + expected_file="expected_output.txt", + test_on_version=">=7.3", + ) + + def test_extended(self): + self.check_rule( + src_files=["test.robot", "tasks.robot"], + expected_file="expected_extended.txt", + output_format="extended", + test_on_version=">=7.3", + )