Skip to content

Commit 8754fb4

Browse files
committed
preserve EOLs
1 parent 71eab51 commit 8754fb4

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

robotidy/transformers/AlignVariablesSection.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,26 @@ def align_rows(self, statements, look_up):
5454
continue
5555
aligned_statement = []
5656
for line in st:
57-
for index, token in enumerate(line[:-1]):
57+
for index, token in enumerate(line[:-2]):
5858
aligned_statement.append(token)
5959
aligned_statement.append(Token(Token.SEPARATOR, (look_up[index] - len(token.value) + 4) * ' '))
60-
aligned_statement.append(line[-1])
61-
aligned_statement.append(Token(Token.EOL, '\n')) # TODO: use global newline
60+
last_token = line[-2]
61+
# remove leading whitespace before token
62+
last_token.value = last_token.value.strip() if last_token.value else last_token.value
63+
aligned_statement.append(last_token)
64+
aligned_statement.append(line[-1]) # eol
6265
aligned_statements.append(Statement.from_tokens(aligned_statement))
6366
return aligned_statements
6467

6568
def tokens_by_lines(self, node):
6669
for index, line in enumerate(node.lines):
67-
if line and line[0].type == Token.VARIABLE and not line[0].value:
68-
# if variable is prefixed with spaces
69-
line = line[1:]
70-
yield [token for token in line if token.type not in ('SEPARATOR', 'EOL', 'EOS')]
70+
if line:
71+
if line[0].type == Token.VARIABLE and not line[0].value:
72+
# if variable is prefixed with spaces
73+
line = line[1:]
74+
elif line[0].type == Token.ARGUMENT:
75+
line[0].value = line[0].value.strip() if line[0].value else line[0].value
76+
yield [token for token in line if token.type not in ('SEPARATOR', 'EOS')]
7177

7278
@staticmethod
7379
def create_look_up(statements):

tests/atest/transformers/AlignVariablesSection/expected/tests.robot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ ${LONGER_NAME_THAT_GOES_AND_GOES} longer value that goes and goes
88
&{MULTILINE} a=b
99
... b=c
1010
... d=1
11+
${invalid}
12+
${invalid_more}

tests/atest/transformers/AlignVariablesSection/source/tests.robot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ ${LONGER_NAME_THAT_GOES_AND_GOES} longer value that goes and goes
88
&{MULTILINE} a=b
99
... b=c
1010
... d=1
11+
${invalid}
12+
${invalid_more}

0 commit comments

Comments
 (0)