diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2023-03-17 08:52:27 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-04-06 15:45:30 +0900 |
commit | d511e6960f4b02731840d4bab381dec73e2c391f (patch) | |
tree | 06b2fd3e5f3d336cf4324e77e76fca6fdc45b00e /lib | |
parent | 63ea6b0cf2b7fd27e22dc7b468fe65ee2c79b23a (diff) | |
download | ruby-d511e6960f4b02731840d4bab381dec73e2c391f.tar.gz |
[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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/syntax_suggest/core_ext.rb | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/syntax_suggest/core_ext.rb b/lib/syntax_suggest/core_ext.rb index f2fbc7ac64..e0fd62b81c 100644 --- a/lib/syntax_suggest/core_ext.rb +++ b/lib/syntax_suggest/core_ext.rb @@ -45,6 +45,8 @@ if SyntaxError.method_defined?(:detailed_message) ) annotation = io.string + annotation += "\n" unless annotation.end_with?("\n") + annotation + message else message |