From ef1801ac80e4f26481e2cdf82f8e422144d47869 Mon Sep 17 00:00:00 2001 From: Zsolt Dollenstein Date: Mon, 17 Jul 2023 21:06:40 +0100 Subject: [PATCH] Don't swallow trailing whitespace --- native/libcst/src/nodes/module.rs | 8 ++------ native/libcst/tests/fixtures/trailing_whitespace.py | 5 +++++ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 native/libcst/tests/fixtures/trailing_whitespace.py diff --git a/native/libcst/src/nodes/module.rs b/native/libcst/src/nodes/module.rs index 656b7d39..ff9a2a73 100644 --- a/native/libcst/src/nodes/module.rs +++ b/native/libcst/src/nodes/module.rs @@ -77,12 +77,8 @@ impl<'r, 'a> Inflate<'a> for DeflatedModule<'r, 'a> { } } if let Some(num) = last_indented { - if num + 1 == footer.len() { - footer = vec![]; - } else { - let (_, rest) = footer.split_at(num + 1); - footer = rest.to_vec(); - } + let (_, rest) = footer.split_at(num); + footer = rest.to_vec(); } } else { swap(&mut header, &mut footer); diff --git a/native/libcst/tests/fixtures/trailing_whitespace.py b/native/libcst/tests/fixtures/trailing_whitespace.py new file mode 100644 index 00000000..5a01c197 --- /dev/null +++ b/native/libcst/tests/fixtures/trailing_whitespace.py @@ -0,0 +1,5 @@ + + +x = 42 +print(x) + \ No newline at end of file