[ruby/syntax_suggest] 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
^~~
```

https://github.com/ruby/syntax_suggest/commit/db4cf9147d
This commit is contained in:
Yusuke Endoh 2023-03-17 08:52:27 +09:00 committed by Hiroshi SHIBATA
parent 63ea6b0cf2
commit d511e6960f

View File

@ -45,6 +45,8 @@ if SyntaxError.method_defined?(:detailed_message)
) )
annotation = io.string annotation = io.string
annotation += "\n" unless annotation.end_with?("\n")
annotation + message annotation + message
else else
message message