From 4431bc2cb7b1e56a314a1e776ea0ef7dbb7623b2 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Fri, 1 Jul 2022 15:11:56 +0800 Subject: [PATCH] fix(fmt): add missing EOF newline (#2177) * fix(fmt): add missing EOF newline * test(fmt): add missing EOL newlines to fmt.sol files --- fmt/src/formatter.rs | 5 ++++- fmt/testdata/ArrayExpressions/fmt.sol | 2 +- fmt/testdata/ForStatement/fmt.sol | 2 +- fmt/testdata/FunctionCallArgsStatement/fmt.sol | 2 +- fmt/testdata/NamedFunctionCallExpression/fmt.sol | 2 +- fmt/testdata/RevertStatement/fmt.sol | 2 +- fmt/testdata/TernaryExpression/fmt.sol | 2 +- fmt/testdata/ThisExpression/fmt.sol | 2 +- fmt/testdata/TryStatement/fmt.sol | 2 +- fmt/testdata/UnitExpression/fmt.sol | 2 +- 10 files changed, 13 insertions(+), 10 deletions(-) diff --git a/fmt/src/formatter.rs b/fmt/src/formatter.rs index 62ba6959d3b2..6d152ef198ed 100644 --- a/fmt/src/formatter.rs +++ b/fmt/src/formatter.rs @@ -1156,6 +1156,9 @@ impl<'a, W: Write> Visitor for Formatter<'a, W> { self.comments.remove_comments_before(self.source.len()); write_chunk!(self, self.source.len(), "{}", comments.trim_end())?; + // EOF newline + writeln!(self.buf())?; + Ok(()) } @@ -2799,7 +2802,7 @@ mod tests { } let expected_comments = Comments::new(expected_comments, expected_source); - let expected = PrettyString(expected_source.trim().to_string()); + let expected = PrettyString(expected_source.to_string()); let mut source_formatted = String::new(); let mut f = Formatter::new(&mut source_formatted, source, source_comments, config.clone()); diff --git a/fmt/testdata/ArrayExpressions/fmt.sol b/fmt/testdata/ArrayExpressions/fmt.sol index d648f90b137a..c0f00d3b1f40 100644 --- a/fmt/testdata/ArrayExpressions/fmt.sol +++ b/fmt/testdata/ArrayExpressions/fmt.sol @@ -67,4 +67,4 @@ contract ArrayExpressions { uint256[1] memory literal3 = [ /* comment11 */ someVeryVeryLongVariableName /* comment13 */ ]; } -} \ No newline at end of file +} diff --git a/fmt/testdata/ForStatement/fmt.sol b/fmt/testdata/ForStatement/fmt.sol index 31eb0a43dcdd..0fac1d2111d0 100644 --- a/fmt/testdata/ForStatement/fmt.sol +++ b/fmt/testdata/ForStatement/fmt.sol @@ -24,4 +24,4 @@ contract ForStatement { "test"; } } -} \ No newline at end of file +} diff --git a/fmt/testdata/FunctionCallArgsStatement/fmt.sol b/fmt/testdata/FunctionCallArgsStatement/fmt.sol index 70bef4fb1c47..9cd091bf8638 100644 --- a/fmt/testdata/FunctionCallArgsStatement/fmt.sol +++ b/fmt/testdata/FunctionCallArgsStatement/fmt.sol @@ -50,4 +50,4 @@ contract FunctionCallArgsStatement { gas: gasleft() }; } -} \ No newline at end of file +} diff --git a/fmt/testdata/NamedFunctionCallExpression/fmt.sol b/fmt/testdata/NamedFunctionCallExpression/fmt.sol index 60617463c5fd..14a24c900388 100644 --- a/fmt/testdata/NamedFunctionCallExpression/fmt.sol +++ b/fmt/testdata/NamedFunctionCallExpression/fmt.sol @@ -44,4 +44,4 @@ contract NamedFunctionCallExpression { // comment8 }); } -} \ No newline at end of file +} diff --git a/fmt/testdata/RevertStatement/fmt.sol b/fmt/testdata/RevertStatement/fmt.sol index 9322c65e7cc9..6a3c7a4ea017 100644 --- a/fmt/testdata/RevertStatement/fmt.sol +++ b/fmt/testdata/RevertStatement/fmt.sol @@ -48,4 +48,4 @@ contract RevertStatement { someVeryLongFunctionNameToGetDynamicErrorMessageString() /* comment17 */ ); } -} \ No newline at end of file +} diff --git a/fmt/testdata/TernaryExpression/fmt.sol b/fmt/testdata/TernaryExpression/fmt.sol index c35a53592672..f76b3b822a9e 100644 --- a/fmt/testdata/TernaryExpression/fmt.sol +++ b/fmt/testdata/TernaryExpression/fmt.sol @@ -20,4 +20,4 @@ contract TernaryExpression { // comment7 : 0; // comment8 } -} \ No newline at end of file +} diff --git a/fmt/testdata/ThisExpression/fmt.sol b/fmt/testdata/ThisExpression/fmt.sol index b067c7d9f5fa..239a6073eae3 100644 --- a/fmt/testdata/ThisExpression/fmt.sol +++ b/fmt/testdata/ThisExpression/fmt.sol @@ -17,4 +17,4 @@ contract ThisExpression { this // comment 4 ); } -} \ No newline at end of file +} diff --git a/fmt/testdata/TryStatement/fmt.sol b/fmt/testdata/TryStatement/fmt.sol index 609f6b4ef349..d49687eb1285 100644 --- a/fmt/testdata/TryStatement/fmt.sol +++ b/fmt/testdata/TryStatement/fmt.sol @@ -71,4 +71,4 @@ contract TryStatement { unknown.handleError(); } catch {} } -} \ No newline at end of file +} diff --git a/fmt/testdata/UnitExpression/fmt.sol b/fmt/testdata/UnitExpression/fmt.sol index a6d86af7386c..b780d4e8ee46 100644 --- a/fmt/testdata/UnitExpression/fmt.sol +++ b/fmt/testdata/UnitExpression/fmt.sol @@ -21,4 +21,4 @@ contract UnitExpression { // comment4 ether; // comment5 } -} \ No newline at end of file +}