From 48f1102e7028702142dd9cda1760879cbf2449a9 Mon Sep 17 00:00:00 2001 From: Bartlomiej Hirsz Date: Thu, 2 Jun 2022 10:08:47 +0200 Subject: [PATCH] Fix SplitTooLongLine breaking long keyword names --- CHANGES.md | 4 ++++ robotidy/transformers/SplitTooLongLine.py | 4 ++-- robotidy/version.py | 2 +- .../expected/feed_until_line_length.robot | 10 ++++++++++ .../expected/feed_until_line_length_4.robot | 10 ++++++++++ .../SplitTooLongLine/expected/split_on_every_arg.robot | 10 ++++++++++ .../expected/split_on_every_arg_4.robot | 10 ++++++++++ .../transformers/SplitTooLongLine/source/tests.robot | 7 +++++++ tests/atest/transformers/__init__.py | 2 -- 9 files changed, 54 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 42c50ac3..e126bdf7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,10 @@ ## Unreleased +## 2.3.1 + +Fix for ``SplitTooLongLine`` transformer breaking keywords with veeery long names ([#314](https://github.com/MarketSquare/robotframework-tidy/issues/314)) + ### Extra ``--indent`` option Robotidy normalizes all whitespaces using the same fixed amount of spaces (configurable via ``--spacecount``). diff --git a/robotidy/transformers/SplitTooLongLine.py b/robotidy/transformers/SplitTooLongLine.py index 10d094e0..10a309ba 100644 --- a/robotidy/transformers/SplitTooLongLine.py +++ b/robotidy/transformers/SplitTooLongLine.py @@ -87,6 +87,8 @@ def is_inline(node): def visit_KeywordCall(self, node): # noqa if all(line[-1].end_col_offset < self.line_length for line in node.lines): return node + if not len(node.data_tokens) > 1: # nothing to split anyway + return node if self.disablers.is_node_disabled(node, full_match=False): return node return self.split_keyword_call(node) @@ -113,11 +115,9 @@ def split_keyword_call(self, node): separator = Token(Token.SEPARATOR, self.formatting_config.separator) indent = node.tokens[0] - split_every_arg = self.split_on_every_arg keyword = node.get_token(Token.KEYWORD) line = [indent, *self.join_on_separator(node.get_tokens(Token.ASSIGN), separator), keyword] if not self.col_fit_in_line(line): - split_every_arg head = [ *self.split_to_multiple_lines(node.get_tokens(Token.ASSIGN), indent=indent, separator=separator), indent, diff --git a/robotidy/version.py b/robotidy/version.py index 202075fc..3a5935a2 100644 --- a/robotidy/version.py +++ b/robotidy/version.py @@ -1 +1 @@ -__version__ = "2.3" +__version__ = "2.3.1" diff --git a/tests/atest/transformers/SplitTooLongLine/expected/feed_until_line_length.robot b/tests/atest/transformers/SplitTooLongLine/expected/feed_until_line_length.robot index 9a86b7f5..1e8db92f 100644 --- a/tests/atest/transformers/SplitTooLongLine/expected/feed_until_line_length.robot +++ b/tests/atest/transformers/SplitTooLongLine/expected/feed_until_line_length.robot @@ -153,3 +153,13 @@ If - else if - else clause Too long inline IF # shall be handled by InlineIf transformer ${var} ${var2} IF $condition != $condition2 Longer Keyword Name ${argument} values ELSE IF $condition2 Short Keyword ${arg} # comment + +Keyword name over the limit + Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" + + ${assign} + ... Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" + + ${assign} + ... ${assign} + ... Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" diff --git a/tests/atest/transformers/SplitTooLongLine/expected/feed_until_line_length_4.robot b/tests/atest/transformers/SplitTooLongLine/expected/feed_until_line_length_4.robot index 030cb0c5..95a101ce 100644 --- a/tests/atest/transformers/SplitTooLongLine/expected/feed_until_line_length_4.robot +++ b/tests/atest/transformers/SplitTooLongLine/expected/feed_until_line_length_4.robot @@ -156,3 +156,13 @@ Too long inline IF # shall be handled by InlineIf transformer ${var} ${var2} IF $condition != $condition2 Longer Keyword Name ... ${argument} values ELSE IF $condition2 Short Keyword ... ${arg} + +Keyword name over the limit + Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" + + ${assign} + ... Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" + + ${assign} + ... ${assign} + ... Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" diff --git a/tests/atest/transformers/SplitTooLongLine/expected/split_on_every_arg.robot b/tests/atest/transformers/SplitTooLongLine/expected/split_on_every_arg.robot index 44b6ca52..e8ae8b9b 100644 --- a/tests/atest/transformers/SplitTooLongLine/expected/split_on_every_arg.robot +++ b/tests/atest/transformers/SplitTooLongLine/expected/split_on_every_arg.robot @@ -324,3 +324,13 @@ If - else if - else clause Too long inline IF # shall be handled by InlineIf transformer ${var} ${var2} IF $condition != $condition2 Longer Keyword Name ${argument} values ELSE IF $condition2 Short Keyword ${arg} # comment + +Keyword name over the limit + Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" + + ${assign} + ... Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" + + ${assign} + ... ${assign} + ... Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" diff --git a/tests/atest/transformers/SplitTooLongLine/expected/split_on_every_arg_4.robot b/tests/atest/transformers/SplitTooLongLine/expected/split_on_every_arg_4.robot index e808973e..670c02a4 100644 --- a/tests/atest/transformers/SplitTooLongLine/expected/split_on_every_arg_4.robot +++ b/tests/atest/transformers/SplitTooLongLine/expected/split_on_every_arg_4.robot @@ -333,3 +333,13 @@ Too long inline IF # shall be handled by InlineIf transformer ... $condition2 ... Short Keyword ... ${arg} + +Keyword name over the limit + Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" + + ${assign} + ... Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" + + ${assign} + ... ${assign} + ... Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" diff --git a/tests/atest/transformers/SplitTooLongLine/source/tests.robot b/tests/atest/transformers/SplitTooLongLine/source/tests.robot index 2853f642..c798df09 100644 --- a/tests/atest/transformers/SplitTooLongLine/source/tests.robot +++ b/tests/atest/transformers/SplitTooLongLine/source/tests.robot @@ -127,3 +127,10 @@ If - else if - else clause Too long inline IF # shall be handled by InlineIf transformer ${var} ${var2} IF $condition != $condition2 Longer Keyword Name ${argument} values ELSE IF $condition2 Short Keyword ${arg} # comment + +Keyword name over the limit + Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" + + ${assign} Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" + + ${assign} ${assign} Enter "${VNFname}" in the field with XPath "//label[contains(text(), 'Product Name')]/../mat-form-field/div/div/div/textarea" diff --git a/tests/atest/transformers/__init__.py b/tests/atest/transformers/__init__.py index 6b342be9..3af72ada 100644 --- a/tests/atest/transformers/__init__.py +++ b/tests/atest/transformers/__init__.py @@ -87,8 +87,6 @@ def compare_file(self, actual_name: str, expected_name: str = None): if not filecmp.cmp(expected, actual): display_file_diff(expected, actual) pytest.fail(f"File {actual_name} is not same as expected") - else: - actual.unlink() def enabled_in_version(self, target_version: Optional[int]) -> bool: if target_version and ROBOT_VERSION.major != target_version: