Skip to content

Parser: Don't output unexpected_token_close_context for <% if %>#824

Merged
marcoroth merged 2 commits into
mainfrom
dont-leak-semicolon-error
Nov 9, 2025
Merged

Parser: Don't output unexpected_token_close_context for <% if %>#824
marcoroth merged 2 commits into
mainfrom
dont-leak-semicolon-error

Conversation

@marcoroth

@marcoroth marcoroth commented Nov 9, 2025

Copy link
Copy Markdown
Owner

This pull request improves the herb_extract_ruby_to_buffer_with_semicolons function, to only output ; when needed.

That way, when you have an actual syntax error in your Ruby code, it won't mention an error about unexpected ";":

Before

CleanShot 2025-11-09 at 02 37 44@2x

After

Instead, it shows you a conditional_predicate_term error.

CleanShot 2025-11-09 at 02 36 56@2x

Resolves #135

@marcoroth marcoroth merged commit eb8b12e into main Nov 9, 2025
24 checks passed
@marcoroth marcoroth deleted the dont-leak-semicolon-error branch November 9, 2025 01:53
marcoroth added a commit that referenced this pull request Nov 9, 2025
)

Follow up to #824, this pull request improves the
`herb_extract_ruby_to_buffer_with_semicolons` function even further, so
that it is also be able to deal ERB comments that have a leading space
on a single line:

```erb
<% if true %><% # Comment here %><%= hello %><% end %>
```

**Before**

<img width="3390" height="834" alt="CleanShot 2025-11-09 at 03 13 24@2x"
src="https://github.com/user-attachments/assets/8344c1b7-ee41-44d9-b5cd-2d605fc986e9"
/>


**After**

Now, we only have a linter offense telling people to use `<%#`, but no
parser errors anymore.

<img width="3384" height="1032" alt="CleanShot 2025-11-09 at 03 14
16@2x"
src="https://github.com/user-attachments/assets/721f1c74-6c06-4c88-a11b-e2e38615df96"
/>
marcoroth added a commit that referenced this pull request Nov 18, 2025
…902)

This pull request changes the way the parser handles the `unexpected
";"` errors.

In #824, we changed the
`herb_extract_ruby_to_buffer_with_semicolons` method to only add
semicolons when needed. This pull request reverts that. But instead of
just outputting the `unexpected ";"` errors (as it was before #824), we
check if the `;` was actually part of the source file.

If it wasn't part of the source file we re-parse this individual
`ERBContentNode` to check for syntax errors in the raw source of that
`ERBContentNode` instead, which shouldn't have the semicolon and thus
shouldn't append the `unexpected ";"` errors.

Resolves #854
Resolves #865
Resolves #899
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.

Parser: Leaking Ruby parse detail: unexpected_token_close_context: unexpected ';'

1 participant