Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## HEAD (unreleased)

- Handle mismatched end when using rescue without begin (https://github.com/zombocom/dead_end/pull/83)
- CLI returns non-zero exit code when syntax error is found (https://github.com/zombocom/dead_end/pull/86)
- Let -v respond with gem version instead of 'unknown' (https://github.com/zombocom/dead_end/pull/82)

Expand Down
2 changes: 1 addition & 1 deletion lib/dead_end/who_dis_syntax_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def on_parse_error(msg)
when /expecting end-of-input/
@unmatched_symbol = :end
@error_symbol = :unmatched_syntax
when /unexpected .* expecting '(?<unmatched_symbol>.*)'/
when /unexpected .* expecting ['`]?(?<unmatched_symbol>[^']*)/
@unmatched_symbol = $1.to_sym if $1
@error_symbol = :unmatched_syntax
when /unexpected `end'/, # Ruby 2.7 and 3.0
Expand Down
43 changes: 33 additions & 10 deletions spec/unit/who_dis_syntax_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,41 @@

module DeadEnd
RSpec.describe WhoDisSyntaxError do
it "determines the type of syntax error to be an unmatched end" do
expect(
WhoDisSyntaxError.new("def foo;").call.error_symbol
).to eq(:missing_end)
context "determines the type of syntax error to be an unmatched end" do
it "with missing or extra end's" do
expect(
WhoDisSyntaxError.new("def foo;").call.error_symbol
).to eq(:missing_end)

expect(
WhoDisSyntaxError.new("def foo; end; end").call.error_symbol
).to eq(:unmatched_syntax)
expect(
WhoDisSyntaxError.new("def foo; end; end").call.error_symbol
).to eq(:unmatched_syntax)

expect(
WhoDisSyntaxError.new("def foo; end; end").call.unmatched_symbol
).to eq(:end)
expect(
WhoDisSyntaxError.new("def foo; end; end").call.unmatched_symbol
).to eq(:end)
end

it "with unexpected rescue" do
source = <<~EOM
def foo
if bar
"baz"
else
"foo"
rescue FooBar
nil
end
EOM

expect(
WhoDisSyntaxError.new(source).call.error_symbol
).to eq(:unmatched_syntax)

expect(
WhoDisSyntaxError.new(source).call.unmatched_symbol
).to eq(:end)
end
end

context "determines the type of syntax error to be an unmatched pipe" do
Expand Down