Repository: MarketSquare/robotframework-robocop
Pull request #1092 (2024-06-14 08:56:34)

Add rule checking that first Argument is in the same line as [Arguments]
Implements rule from #1001

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/MarketSquare/robotframework-robocop/pull/1092?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=MarketSquare) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 96.27%. Comparing base [(`f62508c`)](https://app.codecov.io/gh/MarketSquare/robotframework-robocop/commit/f62508cff6bcaf0f82139e831e40c601aba5c584?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=MarketSquare) to head [(`9d5a5d5`)](https://app.codecov.io/gh/MarketSquare/robotframework-robocop/commit/9d5a5d50688264b7ac409bfa915582118a2f2d5a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=MarketSquare).
> Report is 21 commits behind head on master.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #1092      +/-   ##
==========================================
- Coverage   97.02%   96.27%   -0.76%     
==========================================
  Files          37       38       +1     
  Lines        4670     4829     +159     
==========================================
+ Hits         4531     4649     +118     
- Misses        139      180      +41     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/MarketSquare/robotframework-robocop/pull/1092?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=MarketSquare).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=MarketSquare).

bhirsz: Thanks, good work! Commented few nitpicks

Patch:
diff --git a/robocop/checkers/spacing.py b/robocop/checkers/spacing.py
index 887a96e..e23074b 100644
--- a/robocop/checkers/spacing.py
+++ b/robocop/checkers/spacing.py
@@ -286,6 +286,23 @@ rules = {
         """,
         added_in_version="3.0.0",
     ),
+    "1018": Rule(
+        rule_id="1018",
+        name="first-argument-in-new-line",
+        msg="First argument: '{{ argument_name }}' should be placed on the same line as [Arguments] setting",
+        severity=RuleSeverity.WARNING,
+        added_in_version="5.3.0",
+        docs="""
+        Example of rule violation::
+
+            *** Keywords ***
+            Custom Keyword With Five Required Arguments
+            [Arguments]
+            ...    ${name}
+            ...    ${surname}
+
+        """,
+    ),
 }
 
 
@@ -948,3 +965,25 @@ class LeftAlignedChecker(VisitorChecker):
                         col=indent + 1,
                     )
                     break
+
+
+class ArgumentsChecker(VisitorChecker):
+    reports = ("first-argument-in-new-line",)
+
+    def visit_Arguments(self, node):
+        eol_already = None
+        for t in node.tokens:
+            if t.type == Token.EOL:
+                eol_already = t
+                continue
+            elif t.type == Token.ARGUMENT:
+                if eol_already is not None:
+                    self.report(
+                        "first-argument-in-new-line",
+                        argument_name=t.value,
+                        lineno=eol_already.lineno,
+                        end_lineno=t.lineno,
+                        col=eol_already.end_col_offset,
+                        end_col=t.end_col_offset,
+                    )
+                return


Test patch:
diff --git a/tests/atest/rules/spacing/first_argument_in_new_line/__init__.py b/tests/atest/rules/spacing/first_argument_in_new_line/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/atest/rules/spacing/first_argument_in_new_line/expected_output.txt b/tests/atest/rules/spacing/first_argument_in_new_line/expected_output.txt
new file mode 100644
index 0000000..a9cc6f6
--- /dev/null
+++ b/tests/atest/rules/spacing/first_argument_in_new_line/expected_output.txt
@@ -0,0 +1,7 @@
+test.robot:25:16 [W] 1018 First argument: '${optional_argument}=value' should be placed on the same line as [Arguments] setting
+test.robot:31:16 [W] 1018 First argument: '${some_argument}' should be placed on the same line as [Arguments] setting
+test.robot:37:16 [W] 1018 First argument: '&{named}' should be placed on the same line as [Arguments] setting
+test.robot:43:16 [W] 1018 First argument: '${required}' should be placed on the same line as [Arguments] setting
+test.robot:50:16 [W] 1018 First argument: '@{args}' should be placed on the same line as [Arguments] setting
+test.robot:57:16 [W] 1018 First argument: '@{varargs}' should be placed on the same line as [Arguments] setting
+test.robot:64:16 [W] 1018 First argument: '@{}' should be placed on the same line as [Arguments] setting
\ No newline at end of file
diff --git a/tests/atest/rules/spacing/first_argument_in_new_line/test.robot b/tests/atest/rules/spacing/first_argument_in_new_line/test.robot
new file mode 100644
index 0000000..11973c4
--- /dev/null
+++ b/tests/atest/rules/spacing/first_argument_in_new_line/test.robot
@@ -0,0 +1,68 @@
+*** Settings ***
+Documentation   test
+
+
+*** Test Cases ***
+Test 1
+    [Documentation]    doc
+    No Operation
+
+
+*** Keywords ***
+Correct Keyword
+    [Documentation]  doc
+    [Arguments]    ${argument_1}
+    ...            ${argument_2}
+    Log Many    ${argument_1}    ${argument_2}
+
+Another Correct Keyword
+    [Documentation]  doc
+    [Arguments]    ${optional_argument}=value
+    Log    ${optional_argument}
+
+Keyword With First Arg In New Line
+    [Documentation]  doc
+    [Arguments]
+    ...     ${optional_argument}=value
+    Log    ${optional_argument}
+
+Another Keyword With First Arg In New Line
+    [Documentation]  doc
+    [Arguments]
+    ...     ${some_argument}
+    Log    ${some_argument}
+
+Free Named Only
+    [Documentation]  doc
+    [Arguments]
+    ...    &{named}
+    Log Many    &{named}
+
+Positional And Free Named
+    [Documentation]  doc
+    [Arguments]
+    ...    ${required}
+    ...    &{extra}
+    Log Many    ${required}    &{extra}
+
+Run Program
+    [Documentation]  doc
+    [Arguments]
+    ...    @{args}
+    ...    &{config}
+    No Operation
+
+With Varargs
+    [Documentation]  doc
+    [Arguments]
+    ...    @{varargs}
+    ...    ${named}
+    Log Many    @{varargs}    ${named}
+
+Without Varargs
+    [Documentation]  doc
+    [Arguments]
+    ...    @{}
+    ...    ${first}
+    ...    ${second}
+    Log Many    ${first}    ${second}
diff --git a/tests/atest/rules/spacing/first_argument_in_new_line/test_rule.py b/tests/atest/rules/spacing/first_argument_in_new_line/test_rule.py
new file mode 100644
index 0000000..6f32193
--- /dev/null
+++ b/tests/atest/rules/spacing/first_argument_in_new_line/test_rule.py
@@ -0,0 +1,6 @@
+from tests.atest.utils import RuleAcceptance
+
+
+class TestRuleAcceptance(RuleAcceptance):
+    def test_rule(self):
+        self.check_rule(src_files=["test.robot"], expected_file="expected_output.txt")