Skip to content

Commit 30a2aa7

Browse files
authored
Skip sections with --skip-sections option (#486)
Add --skip-sections option to several transformers. Allows to skip formatting of selected sections. This option is redudant with NormalizeSeparators "sections" options and it was replaced by it.
1 parent efabd7a commit 30a2aa7

31 files changed

+327
-176
lines changed
Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
Robotidy 3.6.0
1+
Robotidy 4.0.0
22
=========================================
33

4+
Major release which contains multiple improvements for external transformers. There are also backward incompatible
5+
changes, including removing ``section`` option from ``NormalizeSeparators`` (replaced with ``skip_sections``).
46

57
You can install the latest available version by running::
68

79
pip install --upgrade robotframework-tidy
810

911
or to install exactly this version::
1012

11-
pip install robotframework-tidy==3.6.0
13+
pip install robotframework-tidy==4.0.0
1214

1315
Rerun the transformation in place
1416
----------------------------------
@@ -81,3 +83,36 @@ list in the ``__init__.py``::
8183
"TransformerA",
8284
"TransformerB"
8385
]
86+
87+
New skip option: --skip-sections #388 #475
88+
-------------------------------------------
89+
90+
It is now possible to skip formatting of whole sections with new ``--skip-sections`` option.
91+
92+
Currently supported in::
93+
94+
AddMissingEnd
95+
DiscardEmptySections
96+
NormalizeAssignments
97+
NormalizeNewLines
98+
NormalizeSectionHeaderName
99+
NormalizeSeparators
100+
SplitTooLongLine
101+
102+
Support for other transformers can be added if needed.
103+
104+
You can configure which section to skip using comma separated list of section names: settings,variables,testcases,tasks,keywords,comments.
105+
Like other skip options it can be used either for all transformers with ``--skip-sections``, or only for configured
106+
transformer::
107+
108+
> robotidy --configure DiscardEmptySections:skip_sections=variables src
109+
110+
Since this option provides the same functionality as ``section`` argument in ``NormalizeSeparators``, the ``section``
111+
option was removed. Note that to replicate the same behaviour, you now need to list sections that you want to skip
112+
rather than the sections you want to format. For example following command::
113+
114+
> robotidy -c NormalizeSeparators:sections=settings,variables,testcases,comments src
115+
116+
Is now equivalent of::
117+
118+
> robotidy -c NormalizeSeparators:skip_sections=keywords

docs/source/configuration/skip_formatting.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ To see what types are possible to skip, see ``Skip formatting`` sections in each
1818

1919
Skip documentation
2020
-------------------
21+
2122
Flag that disables formatting of the documentation. Example usage::
2223

2324
robotidy -c NormalizeSeparators:skip_documentation=True src
@@ -28,6 +29,7 @@ It is possible to use global flag to skip formatting for every transformer that
2829

2930
Configuration file
3031
~~~~~~~~~~~~~~~~~~~~
32+
3133
Both options are configurable using configuration file (:ref:`config-file`).
3234

3335
.. code-block:: toml
@@ -42,6 +44,7 @@ Both options are configurable using configuration file (:ref:`config-file`).
4244

4345
Skip return values
4446
-------------------
47+
4548
Flag that disables formatting of the return values (assignments). Example usage::
4649

4750
robotidy -c AlignKeywordsSection:skip_return_values=True src
@@ -52,6 +55,7 @@ It is possible to use global flag to skip formatting for every transformer that
5255

5356
Configuration file
5457
~~~~~~~~~~~~~~~~~~~~
58+
5559
Both options are configurable using configuration file (:ref:`config-file`).
5660

5761
.. code-block:: toml
@@ -66,6 +70,7 @@ Both options are configurable using configuration file (:ref:`config-file`).
6670

6771
Skip keyword call
6872
------------------
73+
6974
Comma-separated list of keyword call names that should not be formatted. Names will be
7075
normalized before search (spaces and underscores removed, lowercase).
7176

@@ -81,6 +86,7 @@ It is possible to use global option to skip formatting for every transformer tha
8186

8287
Configuration file
8388
~~~~~~~~~~~~~~~~~~~~
89+
8490
Both options are configurable using configuration file (:ref:`config-file`).
8591

8692
.. code-block:: toml
@@ -98,6 +104,7 @@ Both options are configurable using configuration file (:ref:`config-file`).
98104

99105
Skip keyword call pattern
100106
-------------------------
107+
101108
Comma-separated list of keyword call name patterns that should not be formatted. The keyword names are not normalized.
102109
If you're using different case for the same keyword ("Keyword" and "keyword") or using both spaces and underscores, it is
103110
recommended to use proper regex flags to match it properly.
@@ -117,6 +124,7 @@ It is possible to use global option to skip formatting for every transformer tha
117124

118125
Configuration file
119126
~~~~~~~~~~~~~~~~~~~~
127+
120128
Both options are configurable using configuration file (:ref:`config-file`).
121129

122130
.. code-block:: toml
@@ -134,6 +142,7 @@ Both options are configurable using configuration file (:ref:`config-file`).
134142

135143
Skip settings
136144
-------------------
145+
137146
Flag that disables formatting of the settings. Example usage::
138147

139148
robotidy -c AlignTestCasesSection:skip_settings=True src
@@ -157,6 +166,7 @@ Following types are possible to skip:
157166

158167
Configuration file
159168
~~~~~~~~~~~~~~~~~~~~
169+
160170
Option is configurable using configuration file (:ref:`config-file`).
161171

162172
Skip formatting of all settings:
@@ -185,6 +195,7 @@ Skip formatting of selected settings:
185195

186196
Skip comments and block comments
187197
---------------------------------
198+
188199
Flag that disables formatting of the comments and block comments. Example usage::
189200

190201
robotidy -c NormalizeSeparators:skip_comments=True src
@@ -219,3 +230,30 @@ Both options are configurable using configuration file (:ref:`config-file`).
219230
configure = [
220231
"NormalizeSeparators : skip_block_comments = False"
221232
]
233+
234+
.. _skip sections:
235+
236+
Skip sections
237+
---------------
238+
239+
Option that disables formatting of the selected settings. Example usage::
240+
241+
robotidy -c NormalizeSeparators:skip_sections=variables src
242+
243+
It is possible to use global option to skip formatting for every transformer that supports it::
244+
245+
robotidy --skip-sections=keywords,testcases src
246+
247+
Section names can be provided using comma separated list: settings,variables,testcases,keywords,comments.
248+
249+
Configuration file
250+
~~~~~~~~~~~~~~~~~~~~
251+
Both options are configurable using configuration file (:ref:`config-file`).
252+
253+
.. code-block:: toml
254+
255+
[tool.robotidy]
256+
skip-sections = "comments"
257+
configure = [
258+
"NormalizeSeparators : skip_sections = tasks,keywords"
259+
]

docs/source/transformers/AddMissingEnd.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,13 @@ Add missing ``END`` token to FOR loops and IF statements.
4040
END
4141
END
4242
Keyword
43+
44+
Skip formatting
45+
----------------
46+
47+
It is possible to use the following arguments to skip formatting of the code:
48+
49+
- :ref:`skip sections`
50+
51+
It is also possible to use disablers (:ref:`disablers`) but ``skip`` option
52+
makes it easier to skip all instances of given type of the code.

docs/source/transformers/DiscardEmptySections.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,13 @@ section with only comments is always considered as non-empty::
9898
9999
*** Comments ***
100100
# robocop: disable=all
101+
102+
Skip formatting
103+
----------------
104+
105+
It is possible to use the following arguments to skip formatting of the code:
106+
107+
- :ref:`skip sections`
108+
109+
It is also possible to use disablers (:ref:`disablers`) but ``skip`` option
110+
makes it easier to skip all instances of given type of the code.

docs/source/transformers/NormalizeAssignments.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,13 @@ You can configure that behaviour to automatically add desired equal sign with ``
9999
${var} = Keyword1
100100
${var} = Keyword2
101101
${var} = Keyword
102+
103+
Skip formatting
104+
----------------
105+
106+
It is possible to use the following arguments to skip formatting of the code:
107+
108+
- :ref:`skip sections`
109+
110+
It is also possible to use disablers (:ref:`disablers`) but ``skip`` option
111+
makes it easier to skip all instances of given type of the code.

docs/source/transformers/NormalizeNewLines.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,13 @@ language marker:
308308
309309
310310
*** Ustawienia ***
311+
312+
Skip formatting
313+
----------------
314+
315+
It is possible to use the following arguments to skip formatting of the code:
316+
317+
- :ref:`skip sections`
318+
319+
It is also possible to use disablers (:ref:`disablers`) but ``skip`` option
320+
makes it easier to skip all instances of given type of the code.

docs/source/transformers/NormalizeSectionHeaderName.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,13 @@ It is possible to upper case section header names by passing ``uppercase=True``
4040
.. code:: robotframework
4141
4242
*** SETTINGS ***
43+
44+
Skip formatting
45+
----------------
46+
47+
It is possible to use the following arguments to skip formatting of the code:
48+
49+
- :ref:`skip sections`
50+
51+
It is also possible to use disablers (:ref:`disablers`) but ``skip`` option
52+
makes it easier to skip all instances of given type of the code.

docs/source/transformers/NormalizeSeparators.rst

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ It is possible to use the following arguments to skip formatting of the code:
146146
- :ref:`skip keyword call`
147147
- :ref:`skip keyword call pattern`
148148
- :ref:`skip comments`
149+
- :ref:`skip sections`
149150

150151
Documentation is formatted by default. To disable formatting the separators inside documentation, and to only format
151152
indentation, set ``skip_documentation`` to ``True``::
@@ -193,38 +194,12 @@ indentation, set ``skip_documentation`` to ``True``::
193194
... long_arg: Argument long_arg.
194195
Test Case Body
195196
196-
Ignored sections
197-
------------------
198-
199-
You can decide which sections should be transformed by configuring
200-
``sections = comments,settings,variables,keywords,testcases`` param::
201-
202-
robotidy --configure NormalizeSeparators:sections=variables src
203-
204-
.. tab-set::
205-
206-
.. tab-item:: Before
207-
208-
.. code:: robotframework
209-
210-
*** Settings ***
211-
Library library.py WITH NAME alias
212-
213-
Force Tags tag
214-
... tag
215-
216-
*** Variables ***
217-
${var} 1 # only this section will be transformed
218-
219-
.. tab-item:: After
220-
221-
.. code:: robotframework
197+
Skip formatting
198+
----------------
222199

223-
*** Settings ***
224-
Library library.py WITH NAME alias
200+
It is possible to use the following arguments to skip formatting of the code:
225201

226-
Force Tags tag
227-
... tag
202+
- :ref:`skip sections`
228203

229-
*** Variables ***
230-
${var} 1 # only this section will be transformed
204+
It is also possible to use disablers (:ref:`disablers`) but ``skip`` option
205+
makes it easier to skip all instances of given type of the code.

docs/source/transformers/SplitTooLongLine.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ It is possible to use the following arguments to skip formatting of the code:
202202
- :ref:`skip keyword call pattern`
203203
- :ref:`skip settings`
204204
- :ref:`skip comments`
205+
- :ref:`skip sections`
205206

206207
It is also possible to use disablers (:ref:`disablers`) but ``skip`` option
207208
makes it easier to skip all instances of given type of the code.

robotidy/api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010

1111
def get_skip_config(config):
12+
# TODO: Improve it
13+
skip_comments = config.get("skip_comments", False)
1214
skip_documentation = config.get("skip_documentation", False)
1315
skip_return_values = config.get("skip_return_values", False)
1416
skip_keyword_call = config.get("skip_keyword_call", [])
@@ -21,6 +23,8 @@ def get_skip_config(config):
2123
skip_timeout = config.get("skip_timeout", False)
2224
skip_return = config.get("skip_return", False)
2325
skip_tags = config.get("skip_tags", False)
26+
skip_sections = config.get("skip_sections", "")
27+
skip_block_comments = config.get("skip_block_comments", False)
2428
return skip.SkipConfig(
2529
documentation=skip_documentation,
2630
return_values=skip_return_values,
@@ -34,6 +38,9 @@ def get_skip_config(config):
3438
timeout=skip_timeout,
3539
return_statement=skip_return,
3640
tags=skip_tags,
41+
comments=skip_comments,
42+
block_comments=skip_block_comments,
43+
sections=skip_sections,
3744
)
3845

3946

0 commit comments

Comments
 (0)