Skip to content

Commit 7038341

Browse files
committed
Review & refactor whitespace errors rules
1 parent 8faf2a2 commit 7038341

File tree

19 files changed

+277
-0
lines changed

19 files changed

+277
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
"""
2+
Whitespace rules.
3+
4+
Holds rules that are used outside spacing module for now - after redesign to seperate rules/checkers spacing rules
5+
can be moved here.
6+
"""
7+
from robocop.linter.rules import Rule, RuleSeverity
8+
9+
10+
class NotEnoughWhitespaceAfterSettingRule(Rule):
11+
"""
12+
Not enough whitespace after setting.
13+
14+
Provide at least two spaces after setting.
15+
16+
Incorrect code example::
17+
18+
*** Test Cases ***
19+
Test
20+
[Documentation] doc
21+
Keyword
22+
23+
*** Keywords ***
24+
Keyword
25+
[Documentation] This is doc
26+
[Arguments] ${var}
27+
Should Be True ${var}
28+
29+
Correct code::
30+
31+
*** Test Cases ***
32+
Test
33+
[Documentation] doc
34+
Keyword
35+
36+
*** Keywords ***
37+
Keyword
38+
[Documentation] This is doc
39+
[Arguments] ${var}
40+
Should Be True ${var}
41+
42+
"""
43+
44+
name = "not-enough-whitespace-after-setting"
45+
rule_id = "SPC19"
46+
message = "Not enough whitespace after '{setting_name}' setting"
47+
severity = RuleSeverity.ERROR
48+
added_in_version = "1.0.0"
49+
50+
51+
class NotEnoughWhitespaceAfterNewlineMarkerRule(Rule):
52+
"""
53+
Not enough whitespace after newline marker.
54+
55+
Provide at least two spaces after newline marker.
56+
57+
Incorrect code example::
58+
59+
@{LIST} 1
60+
... 2
61+
... 3
62+
63+
Correct code::
64+
65+
@{LIST} 1
66+
... 2
67+
... 3
68+
69+
"""
70+
71+
name = "not-enough-whitespace-after-newline-marker"
72+
rule_id = "SPC20"
73+
message = "Not enough whitespace after '...' marker"
74+
severity = RuleSeverity.ERROR
75+
added_in_version = "1.11.0"
76+
77+
78+
class NotEnoughWhitespaceAfterVariableRule(Rule):
79+
"""
80+
Not enough whitespace after variable.
81+
82+
Provide at least two spaces after variable name.
83+
84+
Incorrect code example::
85+
86+
${variable} 1
87+
${other_var} 2
88+
89+
Correct code::
90+
91+
${variable} 1
92+
${other_var} 2
93+
94+
"""
95+
96+
name = "not-enough-whitespace-after-variable"
97+
rule_id = "SPC21"
98+
message = "Not enough whitespace after '{variable_name}' variable name"
99+
severity = RuleSeverity.ERROR
100+
version = ">=4.0"
101+
added_in_version = "1.11.0"
102+
103+
104+
105+
class NotEnoughWhitespaceAfterSuiteSettingRule(Rule):
106+
"""
107+
Not enough whitespace after suite setting.
108+
109+
Provide at least two spaces after suite setting.
110+
111+
Incorrect code example::
112+
113+
*** Settings ***
114+
Library Collections
115+
Test Tags tag
116+
... tag2
117+
Suite Setup Keyword
118+
119+
Correct code::
120+
121+
*** Settings ***
122+
Library Collections
123+
Test Tags tag
124+
... tag2
125+
Suite Setup Keyword
126+
127+
"""
128+
129+
name = "not-enough-whitespace-after-suite-setting"
130+
rule_id = "SPC22"
131+
message = "Not enough whitespace after '{setting_name}' setting"
132+
severity = RuleSeverity.ERROR
133+
added_in_version = "1.11.0"

tests/linter/rules/whitespace/not_enough_whitespace_after_newline_marker/__init__.py

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test.robot:12:5 [E] SPC20 Not enough whitespace after '...' marker
2+
test.robot:18:5 [E] SPC20 Not enough whitespace after '...' marker
3+
settings_errors.robot:3:1 [E] SPC20 Not enough whitespace after '...' marker
4+
variable_errors.robot:3:1 [E] SPC20 Not enough whitespace after '...' marker
5+
variable_errors.robot:13:1 [E] SPC20 Not enough whitespace after '...' marker
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*** Settings ***
2+
Default Tags tag
3+
... tag2
4+
5+
Force Tags tag
6+
.. tag2
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
*** Settings ***
2+
Documentation doc
3+
4+
5+
*** Test Cases ***
6+
Test
7+
[Documentation] doc
8+
[Tags] sometag
9+
Pass
10+
Keyword
11+
One More ${var}
12+
... ${var2}
13+
14+
15+
*** Keywords ***
16+
Keyword
17+
[Documentation] this is doc
18+
... and new line
19+
No Operation
20+
Pass
21+
No Operation
22+
Fail
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from tests.linter.utils import RuleAcceptance
2+
3+
4+
class TestRuleAcceptance(RuleAcceptance):
5+
def test_rule(self):
6+
self.check_rule(expected_file="expected_output.txt")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*** Variables ***
2+
${var}
3+
... val
4+
.... val
5+
value
6+
7+
&{dict} 1
8+
9+
@{variable} a
10+
... b
11+
.... c
12+
...
13+
...d
14+
15+
*** Keywords ***
16+
[Arguments] 1
17+
value My Keyword
18+
My Keyword ${var} ${value}

tests/linter/rules/whitespace/not_enough_whitespace_after_setting/__init__.py

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test.robot:7:5 [E] SPC19 Not enough whitespace after '[Documentation]' setting
2+
test.robot:20:5 [E] SPC19 Not enough whitespace after '[Arguments]' setting
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
*** Settings ***
2+
Documentation doc
3+
4+
5+
*** Test Cases ***
6+
Test
7+
[Documentation] doc
8+
[Tags] sometag
9+
Pass
10+
Keyword
11+
One More
12+
13+
Test without keyword
14+
${a} ${b} # no Keyword here!!!
15+
16+
17+
*** Keywords ***
18+
Keyword
19+
[Documentation] this is doc
20+
[Arguments] ${var}
21+
No Operation
22+
Pass
23+
No Operation
24+
Fail

0 commit comments

Comments
 (0)