-
Notifications
You must be signed in to change notification settings - Fork 14
Consider if syntax error caused an unexpected variable instead of end #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,25 +18,45 @@ module DeadEnd | |
| ).to eq(:end) | ||
| end | ||
|
|
||
| it "determines the type of syntax error to be an unmatched pipe" do | ||
| source = <<~EOM | ||
| class Blerg | ||
| Foo.call do |a | ||
| end # one | ||
| context "determines the type of syntax error to be an unmatched pipe" do | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @schneems I noticed you are not really using
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My experience with contexts is that they become large and unwieldy and lose their usefulness and then when tests get moved around the indentation makes the diff larger. I'm not strictly against it though. |
||
| it "with unexpected 'end'" do | ||
| source = <<~EOM | ||
| class Blerg | ||
| Foo.call do |a | ||
| end # one | ||
| puts lol | ||
| class Foo | ||
| end # two | ||
| end # three | ||
| EOM | ||
| puts lol | ||
| class Foo | ||
| end # two | ||
| end # three | ||
| EOM | ||
|
|
||
| expect( | ||
| DeadEnd.invalid_type(source).error_symbol | ||
| ).to eq(:unmatched_syntax) | ||
| expect( | ||
| DeadEnd.invalid_type(source).error_symbol | ||
| ).to eq(:unmatched_syntax) | ||
|
|
||
| expect( | ||
| DeadEnd.invalid_type(source).unmatched_symbol | ||
| ).to eq(:|) | ||
| expect( | ||
| DeadEnd.invalid_type(source).unmatched_symbol | ||
| ).to eq(:|) | ||
| end | ||
|
|
||
| it "with unexpected local variable or method" do | ||
| source = <<~EOM | ||
| class Blerg | ||
| [].each do |a | ||
| puts a | ||
| end | ||
| end | ||
| EOM | ||
|
|
||
| expect( | ||
| DeadEnd.invalid_type(source).error_symbol | ||
| ).to eq(:unmatched_syntax) | ||
|
|
||
| expect( | ||
| DeadEnd.invalid_type(source).unmatched_symbol | ||
| ).to eq(:|) | ||
| end | ||
| end | ||
|
|
||
| it "determines the type of syntax error to be an unmatched bracket" do | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding a case statement above the
unexpected endcase. Something like:I'm wondering if that will allow us to simplify this a bit. My worry is the larger this case becomes the more likely accidentally firing this logic on an unrelated parse error becomes larger. By moving the "expecting " logic above this case in the detection, we can avoid trying to catch some of these seemingly unrelated other exception types.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schneems thanks, updated! Let me know what you think.
I checked and the only one that doesn't match that regexp now is unexpected `end' so I left that one there, and the rest are covered by that new regexp now 👍
Also had to use
$1instead, because for some reason$LAST_MATCH_INFOcomes back asnil🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I had to also leave the cases for 2.5 and 2.6, although we could use a regex there too.. what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, exactly what I had in mind