Skip to content

Commit 544fb1d

Browse files
authored
Add skip_documentation parameter to NormalizeSeparators (#308)
1 parent f172c72 commit 544fb1d

File tree

16 files changed

+154
-12
lines changed

16 files changed

+154
-12
lines changed

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ Keyword
1919
END
2020
```
2121

22+
### ``skip_documentation`` for NormalizeSeparators
23+
24+
It is now possible to skip formatting suite, test case and keyword documentation with NormalizeSeparator transformer
25+
by using ``skip_documentation`` parameter ([#300](https://github.com/MarketSquare/robotframework-tidy/issues/300)):
26+
27+
```
28+
robotidy --configure NormalizeSeparators:skip_documentation=True src
29+
```
30+
31+
2232
## 2.3
2333

2434
### Prettified output

docs/source/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
sphinx-tabs==3.2.0
1+
sphinx-tabs==3.3.1
22
sphinx-copybutton==0.3.3

docs/source/transformers/NormalizeSeparators.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,49 @@ Combine it with ``spacecount`` to set whitespace separately for indent and separ
126126
Keyword With ${var}
127127
END
128128

129+
Formatting documentation
130+
--------------------------
131+
132+
Documentation is formatted by default. To disable formatting the separators inside documentation, and to only format
133+
indentation, set ``skip_documentation`` to ``True``::
134+
135+
robotidy --configure NormalizeSeparators:skip_documentation=True src
136+
137+
.. tabs::
138+
139+
.. code-tab:: robotframework Before
140+
141+
TEST_TC
142+
[Argument] ${a} ${long_arg}
143+
[Documentation] Test Doc.
144+
...
145+
... Arguments:
146+
... a: Argument A
147+
... long_arg: Argument long_arg.
148+
Test Case Body
149+
150+
.. code-tab:: robotframework skip_documentation=False (default)
151+
152+
TEST_TC
153+
[Argument] ${a} ${long_arg}
154+
[Documentation] Test Doc.
155+
...
156+
... Arguments:
157+
... a: Argument A
158+
... long_arg: Argument long_arg.
159+
Test Case Body
160+
161+
.. code-tab:: robotframework skip_documentation=True
162+
163+
TEST_TC
164+
[Argument] ${a} ${long_arg}
165+
[Documentation] Test Doc.
166+
...
167+
... Arguments:
168+
... a: Argument A
169+
... long_arg: Argument long_arg.
170+
Test Case Body
171+
129172
Ignored sections
130173
---------------
131174

noxfile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ def install_doc_deps(session, robot_major_ver):
1919

2020

2121
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
22-
@nox.parametrize('robot_version', ["stable4", "stable5"])
22+
@nox.parametrize("robot_version", ["stable4", "stable5"])
2323
def unit(session, robot_version):
2424
install_dev_deps(session, robot_version)
25-
session.run('pytest', 'tests')
25+
session.run("pytest", "tests")
2626

2727

2828
@nox.session(python=DEFAULT_PYTHON_VERSION)
2929
def coverage(session):
3030
install_dev_deps(session, "stable5")
3131
session.install("coverage")
32-
session.run('coverage', 'run', '-m', 'pytest')
33-
session.run('coverage', 'html')
32+
session.run("coverage", "run", "-m", "pytest")
33+
session.run("coverage", "html")
3434

3535

3636
@nox.session(python=DEFAULT_PYTHON_VERSION)
3737
def docs(session):
3838
install_doc_deps(session, "stable5")
39-
session.run('sphinx-build', '-b', 'html', 'docs/source', 'docs/_build/')
39+
session.run("sphinx-build", "-b", "html", "docs/source", "docs/_build/")

robotidy/transformers/NormalizeSeparators.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ class NormalizeSeparators(ModelTransformer):
2121
You can decide which sections should be transformed by configuring
2222
``sections = comments,settings,variables,keywords,testcases`` param.
2323
24+
To not format documentation configure ``skip_documentation`` to ``True``.
25+
2426
Supports global formatting params: ``--startline`` and ``--endline``.
2527
"""
2628

27-
def __init__(self, sections: str = None):
29+
def __init__(self, sections: str = None, skip_documentation: bool = False):
2830
self.indent = 0
2931
self.sections = self.parse_sections(sections)
32+
self.skip_documentation = skip_documentation
3033
self.is_inline = False
3134

3235
def parse_sections(self, sections):
@@ -129,12 +132,18 @@ def visit_If(self, node):
129132
self.is_inline = False
130133
return node
131134

135+
def visit_Documentation(self, doc): # noqa
136+
if self.skip_documentation:
137+
has_pipes = doc.tokens[0].value.startswith("|")
138+
return self._handle_spaces(doc, has_pipes, only_indent=True)
139+
return self.visit_Statement(doc)
140+
132141
@skip_if_disabled
133142
def visit_Statement(self, statement): # noqa
134143
has_pipes = statement.tokens[0].value.startswith("|")
135144
return self._handle_spaces(statement, has_pipes)
136145

137-
def _handle_spaces(self, statement, has_pipes):
146+
def _handle_spaces(self, statement, has_pipes, only_indent=False):
138147
new_tokens = []
139148
for line in statement.lines:
140149
prev_sep = False
@@ -145,7 +154,7 @@ def _handle_spaces(self, statement, has_pipes):
145154
prev_sep = True
146155
if index == 0:
147156
token.value = self.formatting_config.indent * self.indent
148-
else:
157+
elif not only_indent:
149158
token.value = self.formatting_config.separator
150159
else:
151160
prev_sep = False

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
"doc": [
6060
"sphinx_rtd_theme",
6161
"sphinx",
62+
"sphinx-tabs==3.3.1",
63+
"sphinx-copybutton==0.3.3",
6264
],
6365
},
6466
entry_points={"console_scripts": ["robotidy=robotidy.cli:cli"]},

tests/atest/transformers/NormalizeSeparators/expected/comment_keywords.robot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ${var} 3
1717
*** Test Cases ***
1818
Test case
1919
[Setup] Keyword
20+
[Documentation] First word Second word
2021
Keyword with arg
2122
... and multi lines
2223
[Teardown] Keyword
@@ -33,6 +34,8 @@ Test case with structures
3334
Keyword
3435
Another Keyword
3536
[Arguments] ${arg}
37+
[Documentation] First word Second word
38+
... Third.
3639
Should Be Equal 1
3740
... ${arg}
3841
IF ${condition}

tests/atest/transformers/NormalizeSeparators/expected/comments_settings_variable_keywords_testcases.robot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ${var} 3
1717
*** Test Cases ***
1818
Test case
1919
[Setup] Keyword
20+
[Documentation] First word Second word
2021
Keyword with arg
2122
... and multi lines
2223
[Teardown] Keyword
@@ -33,6 +34,8 @@ Test case with structures
3334
Keyword
3435
Another Keyword
3536
[Arguments] ${arg}
37+
[Documentation] First word Second word
38+
... Third.
3639
Should Be Equal 1
3740
... ${arg}
3841
IF ${condition}

tests/atest/transformers/NormalizeSeparators/expected/comments_settings_variables.robot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ${var} 3
1717
*** Test Cases ***
1818
Test case
1919
[Setup] Keyword
20+
[Documentation] First word Second word
2021
Keyword with arg
2122
... and multi lines
2223
[Teardown] Keyword
@@ -33,6 +34,8 @@ Test case with structures
3334
Keyword
3435
Another Keyword
3536
[Arguments] ${arg}
37+
[Documentation] First word Second word
38+
... Third.
3639
Should Be Equal 1
3740
... ${arg}
3841
IF ${condition}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# this is comment
2+
3+
*** Settings ***
4+
Library library.py WITH NAME alias
5+
6+
Force Tags tag
7+
... tag
8+
9+
Documentation doc
10+
... multi
11+
... line
12+
13+
*** Variables ***
14+
${var} 3
15+
${var2} 4
16+
17+
*** Test Cases ***
18+
Test case
19+
[Setup] Keyword
20+
[Documentation] First word Second word
21+
Keyword with arg
22+
... and multi lines
23+
[Teardown] Keyword
24+
25+
Test case with structures
26+
FOR ${variable} IN 1 2
27+
Keyword
28+
IF ${condition}
29+
Log ${stuff} console=True
30+
END
31+
END
32+
33+
*** Keywords ***
34+
Keyword
35+
Another Keyword
36+
[Arguments] ${arg}
37+
[Documentation] First word Second word
38+
... Third.
39+
Should Be Equal 1
40+
... ${arg}
41+
IF ${condition}
42+
FOR ${v} IN RANGE 10
43+
Keyword
44+
END
45+
END
46+
47+
Keyword With Tabulators
48+
Keyword
49+
... 2
50+
... ${arg}

0 commit comments

Comments
 (0)