From db4cf9147da65701c5b0d3b78d55418c774bdb32 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 17 Mar 2023 08:52:27 +0900 Subject: [PATCH] The annotation must end with a new line syntax_suggest did not work great when there is no new line at the end of the input file. Input: ``` def foo end end # No newline at end of file ``` Previous output: ``` $ ruby test.rb test.rb: --> test.rb Unmatched `end', missing keyword (`do', `def`, `if`, etc.) ? > 1 def foo > 2 end > 3 end # No newline at end of filetest.rb:3: syntax error, unexpected `end' (SyntaxError) end # No newline at end of file ^~~ ``` Note that "test.rb:3: ..." is appended to the last line of the annotation. This change makes sure that the annotation ends with a new line. New output: ``` $ ruby test.rb test.rb: --> test.rb Unmatched `end', missing keyword (`do', `def`, `if`, etc.) ? > 1 def foo > 2 end > 3 end # No newline at end of file test.rb:3: syntax error, unexpected `end' (SyntaxError) end # No newline at end of file ^~~ ``` --- lib/syntax_suggest/core_ext.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/syntax_suggest/core_ext.rb b/lib/syntax_suggest/core_ext.rb index f2fbc7a..e0fd62b 100644 --- a/lib/syntax_suggest/core_ext.rb +++ b/lib/syntax_suggest/core_ext.rb @@ -45,6 +45,8 @@ def detailed_message(highlight: true, syntax_suggest: true, **kwargs) ) annotation = io.string + annotation += "\n" unless annotation.end_with?("\n") + annotation + message else message