Skip to content

Commit

Permalink
Ignore invalid sections in MergeAndOrderSections
Browse files Browse the repository at this point in the history
  • Loading branch information
bhirsz committed Jul 30, 2023
1 parent 496b826 commit 6d9b2cf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/releasenotes/4.4.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ Robot Framework 6.1 fixes (#550)

- ``Translate`` transformer should now properly handle creating Comments section (if needed),
- Missing settings translations should now be ignored by ``Translate`` transformer,
- Files with invalid sections (for example unrecognized translated section names) should be ignored by
``MergeAndOrderSections``
6 changes: 6 additions & 0 deletions robotidy/transformers/MergeAndOrderSections.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from robot.api.parsing import Config # from RF 6.0
except ImportError:
Config = None
try:
from robot.parsing.model import InvalidSection # from RF 6.1
except ImportError:
InvalidSection = None
from robotidy.transformers import Transformer


Expand Down Expand Up @@ -119,6 +123,8 @@ def visit_File(self, node): # noqa
for index, section in enumerate(node.sections):
if index == last:
section = self.from_last_section(section)
if InvalidSection and isinstance(section, InvalidSection):
return node
section_type = self.get_section_type(section)
if section_type not in sections:
sections[section_type] = section
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*** Ustawienia ***

*** Testy ***
Test
No Operation
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ def test_disablers(self):

def test_translated(self):
self.compare(source="translated.robot", target_version=">=6")

def test_invalid(self):
self.compare(source="invalid.robot", not_modified=True, target_version=">=6.1")

0 comments on commit 6d9b2cf

Please sign in to comment.