ruby / ruby/syntax_suggest

Accidental if instead of a block

Open
#206 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
350
Forks
17
Avg merge
48m
Merged PRs (30d)
5

Description

I don't know if we can improve this but I hit this syntax error today when writing rspec:

Unmatched keyword, missing `end' ?
  2  describe "something" do
> 3    if "does something" do
> 5    end
  6  end
/tmp/scratchrb:3: syntax error, unexpected `do', expecting `then' or ';' or '\n' (SyntaxError)
  if "does something" do
                      ^~

(I used if instead of it).

Both if and do need an end. I think we could explain this better. In this case the original error says "unexpected do', expecting then' or ';' or '\n'". Perhaps as we're trying to explain the problem we should verify that the syntax error of our captured block matches the syntax error of the document, do something differently.

Generated by this code:

describe "something" do
  if "does something" do
    print "foo"
  end
end

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided Ruby snippet and compare its original syntax error with syntax_suggest's explanation. Trace the handling of this captured block and determine how the reported do error should be distinguished from the surrounding missing end; done means the tool gives a clearer explanation for this if-instead-of-it case.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.