Skip to content

Commit 7089502

Browse files
committed
Fix a bug in the python leading whitespace calculation.
1 parent 33a7a48 commit 7089502

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

python/selfie-lib/selfie_lib/EscapeLeadingWhitespace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def appropriate_for(cls, file_content: str) -> "EscapeLeadingWhitespace":
3333
common_whitespace = None
3434

3535
for line in file_content.splitlines():
36-
whitespace = "".join(c for c in line if c.isspace())
36+
whitespace = line[0 : len(line) - len(line.lstrip())]
3737
if whitespace == "" or whitespace == " ":
3838
continue
3939
elif all(c == " " for c in whitespace):

python/selfie-lib/tests/EscapeLeadingWhitespace_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ def test_detection():
4646
)
4747

4848
# single spaces and tabs -> only tabs need escape
49+
tab = "\t"
4950
test_string = f"""/*
5051
* Copyright
5152
*/
5253
interface Foo [
53-
{'\t'} bar()
54+
{tab}bar()
5455
]"""
5556
assert (
5657
EscapeLeadingWhitespace.appropriate_for(test_string)
57-
== EscapeLeadingWhitespace.ALWAYS
58+
== EscapeLeadingWhitespace.ONLY_ON_SPACE
5859
)

0 commit comments

Comments
 (0)