Repository: MarketSquare/robotframework-robocop
Pull request #1287 (2025-03-04 11:19:58)

Fix invalid-setting reported as not-enough-whitespace-after-suite-setting


Patch:
diff --git a/docs/releasenotes/6.0.0dev1.rst b/docs/releasenotes/6.0.0dev1.rst
index 4768abd..5c224b5 100644
--- a/docs/releasenotes/6.0.0dev1.rst
+++ b/docs/releasenotes/6.0.0dev1.rst
@@ -668,3 +668,12 @@ Following code will now report invalid ``[Metadata]`` setting use::
         [Invalid]    reported before
         [Metadata]    not reported
         Keyword
+
+Not enough whitespace error is reported instead of invalid setting (#1286)
+--------------------------------------------------------------------------
+
+Following code will now report ``invalid-setting`` instead off ``not-enough-whitespace-after-suite-setting``::
+
+    *** Test Cases ***
+    Keyword
+        [Doc Umentation]
diff --git a/src/robocop/linter/rules/errors.py b/src/robocop/linter/rules/errors.py
index e5d560e..df1cfd1 100644
--- a/src/robocop/linter/rules/errors.py
+++ b/src/robocop/linter/rules/errors.py
@@ -439,7 +439,7 @@ class ParsingErrorChecker(VisitorChecker):
                 end_col=token.end_col_offset + 1,
             )
         else:
-            suite_sett_cand = setting_error.replace(" ", "").lower()
+            suite_sett_cand = node.data_tokens[0].value.replace(" ", "").lower()
             for setting in self.suite_settings:
                 if suite_sett_cand.startswith(setting):
                     if setting_error[0].strip():  # filter out "suite-setting-should-be-left-aligned"


Test patch:
diff --git a/tests/linter/rules/errors/non_existing_setting/expected_extended.txt b/tests/linter/rules/errors/non_existing_setting/expected_extended.txt
index 61b5a40..66fa760 100644
--- a/tests/linter/rules/errors/non_existing_setting/expected_extended.txt
+++ b/tests/linter/rules/errors/non_existing_setting/expected_extended.txt
@@ -1,30 +1,38 @@
-test.robot:11:5 ERR08 Non-existing setting 'Invalid'
-    |
-  9 |
- 10 | *** Test Case ***
- 11 |     [Invalid]  arg
-    |     ^^^^^^^^^ ERR08
- 12 |     [Arguments]  ${arg}
- 13 |     [Return]    ${value}
-    |
-
-test.robot:16:5 ERR08 Non-existing setting 'Argument'. Did you mean: Arguments
-    |
- 14 |
- 15 | *** Keywords ***
- 16 |     [Argument]   ${value}
-    |     ^^^^^^^^^^ ERR08
- 17 |     [Invalid]    arg
- 18 |     [Setup]    ${arg}
-    |
-
-test.robot:17:5 ERR08 Non-existing setting 'Invalid'
-    |
- 15 | *** Keywords ***
- 16 |     [Argument]   ${value}
- 17 |     [Invalid]    arg
-    |     ^^^^^^^^^ ERR08
- 18 |     [Setup]    ${arg}
- 19 |     [Template]    Keyword
-    |
-
+test.robot:11:5 ERR08 Non-existing setting 'Invalid'
+    |
+  9 |
+ 10 | *** Test Case ***
+ 11 |     [Invalid]  arg
+    |     ^^^^^^^^^ ERR08
+ 12 |     [Arguments]  ${arg}
+ 13 |     [Return]    ${value}
+    |
+
+test.robot:16:5 ERR08 Non-existing setting 'Argument'. Did you mean: Arguments
+    |
+ 14 |
+ 15 | *** Keywords ***
+ 16 |     [Argument]   ${value}
+    |     ^^^^^^^^^^ ERR08
+ 17 |     [Invalid]    arg
+ 18 |     [Setup]    ${arg}
+    |
+
+test.robot:17:5 ERR08 Non-existing setting 'Invalid'
+    |
+ 15 | *** Keywords ***
+ 16 |     [Argument]   ${value}
+ 17 |     [Invalid]    arg
+    |     ^^^^^^^^^ ERR08
+ 18 |     [Setup]    ${arg}
+ 19 |     [Template]    Keyword
+    |
+
+test.robot:20:5 ERR08 Non-existing setting 'Doc Umentation'. Did you mean: Documentation
+    |
+ 18 |     [Setup]    ${arg}
+ 19 |     [Template]    Keyword
+ 20 |     [Doc Umentation]
+    |     ^^^^^^^^^^^^^^^^ ERR08
+    |
+
diff --git a/tests/linter/rules/errors/non_existing_setting/expected_output.txt b/tests/linter/rules/errors/non_existing_setting/expected_output.txt
index 905e583..0127149 100644
--- a/tests/linter/rules/errors/non_existing_setting/expected_output.txt
+++ b/tests/linter/rules/errors/non_existing_setting/expected_output.txt
@@ -1,3 +1,4 @@
-test.robot:11:5 [E] ERR08 Non-existing setting 'Invalid'
-test.robot:16:5 [E] ERR08 Non-existing setting 'Argument'. Did you mean: Arguments
-test.robot:17:5 [E] ERR08 Non-existing setting 'Invalid'
\ No newline at end of file
+test.robot:11:5 [E] ERR08 Non-existing setting 'Invalid'
+test.robot:16:5 [E] ERR08 Non-existing setting 'Argument'. Did you mean: Arguments
+test.robot:17:5 [E] ERR08 Non-existing setting 'Invalid'
+test.robot:20:5 [E] ERR08 Non-existing setting 'Doc Umentation'. Did you mean: Documentation
\ No newline at end of file
diff --git a/tests/linter/rules/errors/non_existing_setting/test.robot b/tests/linter/rules/errors/non_existing_setting/test.robot
index 7812144..76b8e5d 100644
--- a/tests/linter/rules/errors/non_existing_setting/test.robot
+++ b/tests/linter/rules/errors/non_existing_setting/test.robot
@@ -1,19 +1,20 @@
-*** Settings ***
-Default Tags  tag
-... tag2
-
-Force Tags  tag
-..    tag2
-
-  Library  Collections
-
-*** Test Case ***
-    [Invalid]  arg
-    [Arguments]  ${arg}
-    [Return]    ${value}
-
-*** Keywords ***
-    [Argument]   ${value}
-    [Invalid]    arg
-    [Setup]    ${arg}
-    [Template]    Keyword
\ No newline at end of file
+*** Settings ***
+Default Tags  tag
+... tag2
+
+Force Tags  tag
+..    tag2
+
+  Library  Collections
+
+*** Test Case ***
+    [Invalid]  arg
+    [Arguments]  ${arg}
+    [Return]    ${value}
+
+*** Keywords ***
+    [Argument]   ${value}
+    [Invalid]    arg
+    [Setup]    ${arg}
+    [Template]    Keyword
+    [Doc Umentation]
diff --git a/tests/linter/rules/whitespace/not_enough_whitespace_after_setting/test.robot b/tests/linter/rules/whitespace/not_enough_whitespace_after_setting/test.robot
index 6695e34..412f197 100644
--- a/tests/linter/rules/whitespace/not_enough_whitespace_after_setting/test.robot
+++ b/tests/linter/rules/whitespace/not_enough_whitespace_after_setting/test.robot
@@ -1,24 +1,27 @@
-*** Settings ***
-Documentation  doc
-
-
-*** Test Cases ***
-Test
-    [Documentation] doc
-    [Tags]  sometag
-    Pass
-    Keyword
-    One More
-
-Test without keyword
-    ${a}    ${b}    # no Keyword here!!!
-
-
-*** Keywords ***
-Keyword
-    [Documentation]  this is doc
-    [Arguments] ${var}
-    No Operation
-    Pass
-    No Operation
-    Fail
+*** Settings ***
+Documentation  doc
+
+
+*** Test Cases ***
+Test
+    [Documentation] doc
+    [Tags]  sometag
+    Pass
+    Keyword
+    One More
+
+Test without keyword
+    ${a}    ${b}    # no Keyword here!!!
+
+
+*** Keywords ***
+Keyword
+    [Documentation]  this is doc
+    [Arguments] ${var}
+    No Operation
+    Pass
+    No Operation
+    Fail
+
+Keyword With Invalid Documentation
+    [Doc Umentation]
diff --git a/tests/linter/rules/whitespace/not_enough_whitespace_after_suite_setting/test.robot b/tests/linter/rules/whitespace/not_enough_whitespace_after_suite_setting/test.robot
index 6957309..55192f1 100644
--- a/tests/linter/rules/whitespace/not_enough_whitespace_after_suite_setting/test.robot
+++ b/tests/linter/rules/whitespace/not_enough_whitespace_after_suite_setting/test.robot
@@ -1,21 +1,25 @@
-*** Settings ***
-Library Collections
-Resource file.robot
-Variablesvars.yaml
-
-Force Tags tag
-...    tag2
-Default Tagstag1    tag2
-
-Invalid  ${argument}
-
-Timeout 1min
-Suite Setup Keyword
-Suite Teardown Keyword2
-
-Test Setup Keyword
-Test Teardown Keyword2
-Testtimeout 1min
-Documentation this is doc
-
-Metadata key value
+*** Settings ***
+Library Collections
+Resource file.robot
+Variablesvars.yaml
+
+Force Tags tag
+...    tag2
+Default Tagstag1    tag2
+
+Invalid  ${argument}
+
+Timeout 1min
+Suite Setup Keyword
+Suite Teardown Keyword2
+
+Test Setup Keyword
+Test Teardown Keyword2
+Testtimeout 1min
+Documentation this is doc
+
+Metadata key value
+
+*** Keywords ***
+Keyword With Invalid Setting
+    [Doc Umentation]