Skip to content

Commit

Permalink
Skip documentation formatting if configured in AlignSettingsSection (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bhirsz authored Feb 1, 2024
1 parent 2884e59 commit 776b2ac
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 6 deletions.
24 changes: 24 additions & 0 deletions docs/releasenotes/4.9.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
:orphan:

==============
Robotidy 4.9.0
==============

Support skipping documentation in AlignSettingsSection with ``AlignSettingsSection:skip_documentation=True``
or ``--skip-documentation`` skip options (#622).

You can install the latest available version by running

::

pip install --upgrade robotframework-tidy

or to install exactly this version

::

pip install robotframework-tidy==4.9.0

.. contents::
:depth: 2
:local:
10 changes: 10 additions & 0 deletions docs/source/transformers/AlignSettingsSection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,13 @@ AlignSettingsSection does also support global formatting params ``startline`` an
Metadata Version 2.0 # this should be not aligned
Metadata More Info For more information about *Robot Framework* see http://robotframework.org
Metadata Executed At {HOST}
Skip formatting
----------------
It is possible to use the following arguments to skip formatting of the code:

- :ref:`skip documentation`

It is highly recommended to use one of the ``skip`` options if you wish to use the alignment but you have part of the code
that looks better with manual alignment. It is also possible to use disablers (:ref:`disablers`) but ``skip`` option
makes it easier to skip all instances of given type of the code.
24 changes: 19 additions & 5 deletions robotidy/transformers/AlignSettingsSection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from collections import defaultdict

from robot.api.parsing import Token
from robot.api.parsing import Documentation, Token
from robot.parsing.model import Statement

from robotidy.disablers import skip_section_if_disabled
from robotidy.skip import Skip
from robotidy.transformers import Transformer
from robotidy.utils import misc

Expand Down Expand Up @@ -69,9 +70,17 @@ class AlignSettingsSection(Transformer):
Token.LIBRARY,
Token.VARIABLES,
}

def __init__(self, up_to_column: int = 2, argument_indent: int = 4, min_width: int = None, fixed_width: int = None):
super().__init__()
HANDLES_SKIP = frozenset({"skip_documentation"})

def __init__(
self,
up_to_column: int = 2,
argument_indent: int = 4,
min_width: int = None,
fixed_width: int = None,
skip: Skip = None,
):
super().__init__(skip=skip)
self.up_to_column = up_to_column - 1
self.argument_indent = argument_indent
self.min_width = min_width
Expand All @@ -81,7 +90,7 @@ def __init__(self, up_to_column: int = 2, argument_indent: int = 4, min_width: i
def visit_SettingSection(self, node): # noqa
statements = []
for child in node.body:
if self.disablers.is_node_disabled(child):
if self.disablers.is_node_disabled(child) or self.is_node_skip(child):
statements.append(child)
elif child.type in (Token.EOL, Token.COMMENT):
statements.append(misc.left_align(child))
Expand All @@ -94,6 +103,11 @@ def visit_SettingSection(self, node): # noqa
node.body = self.align_rows(statements, look_up)
return node

def is_node_skip(self, node):
if isinstance(node, Documentation) and self.skip.documentation:
return True
return False

def should_indent_arguments(self, statement):
statement_type = statement[0][0].type
is_library = statement_type == Token.LIBRARY
Expand Down
2 changes: 1 addition & 1 deletion robotidy/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "4.8.1"
__version__ = "4.9.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
*** Settings ***
# whole line comment that should be ignored
Resource ..${/}resources${/}resource.robot
Library SeleniumLibrary
Library Mylibrary.py
Variables variables.py
Test Timeout 1 min

# this should be left aligned
Library CustomLibrary WITH NAME name
Library ArgsedLibrary ${1} ${2} ${3}

Documentation Example using the space separated format.
... and this documentation is multiline
... where this line should go I wonder?
Default Tags default tag 1 default tag 2 default tag 3 default tag 4 default tag 5
Test Setup Open Application App A
Test Teardown Close Application

Metadata Version 2.0
Metadata More Info For more information about *Robot Framework* see http://robotframework.org
Metadata Executed At {HOST}
# this should be left aligned
Test Template

*** Keywords ***
Keyword
Keyword A
Keyword B
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ def test_min_width_shorter(self, min_width):
@pytest.mark.parametrize("min_width", [49, 50, 51, 52])
def test_min_width_longer(self, min_width):
self.compare(source="test.robot", expected="test_min_width_50_width.robot", config=f":min_width={min_width}")

@pytest.mark.parametrize("skip_config", [" --skip-documentation", ":skip_documentation=True"])
def test_skip_documentation(self, skip_config):
self.compare(source="test.robot", expected="test_skip_documentation.robot", config=skip_config)

0 comments on commit 776b2ac

Please sign in to comment.