Skip to content

Conversation

@mame
Copy link
Member

@mame mame commented Mar 17, 2023

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
^~~

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
^~~
```
Copy link
Collaborator

@schneems schneems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@schneems schneems merged commit 0e5e6a2 into ruby:main Mar 17, 2023
@schneems
Copy link
Collaborator

Added a test and changelog entry in #183. I'll release this as 1.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants