From ace9eab8b54d354835b715327a2e736c762c7bf0 Mon Sep 17 00:00:00 2001 From: Mauro Otonelli Date: Wed, 10 Feb 2021 00:36:56 -0300 Subject: [PATCH 1/2] Added missing backtick on 'unmatched unknown detected' --- lib/dead_end/display_invalid_blocks.rb | 2 +- spec/unit/display_invalid_blocks_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/dead_end/display_invalid_blocks.rb b/lib/dead_end/display_invalid_blocks.rb index 11b5c4d..44a7529 100644 --- a/lib/dead_end/display_invalid_blocks.rb +++ b/lib/dead_end/display_invalid_blocks.rb @@ -82,7 +82,7 @@ def banner closed: `{ }`. EOM else - "DeadEnd: Unmatched #{@invalid_obj.unmatched_symbol}` detected" + "DeadEnd: Unmatched `#{@invalid_obj.unmatched_symbol}` detected" end end diff --git a/spec/unit/display_invalid_blocks_spec.rb b/spec/unit/display_invalid_blocks_spec.rb index b78629d..e92ed23 100644 --- a/spec/unit/display_invalid_blocks_spec.rb +++ b/spec/unit/display_invalid_blocks_spec.rb @@ -51,6 +51,24 @@ class Cat expect(display.banner).to include("DeadEnd: Unmatched `end` detected") end + it "Unmatched unknown banner" do + source = <<~EOM + class Cat + def meow + 1 * + end + end + EOM + code_lines = code_line_array(source) + + display = DisplayInvalidBlocks.new( + code_lines: code_lines, + blocks: CodeBlock.new(lines: code_lines), + invalid_obj: WhoDisSyntaxError.new(source), + ) + expect(display.banner).to include("DeadEnd: Unmatched `unknown` detected") + end + it "missing end banner" do source = <<~EOM class Cat From a2ffec222acf0cac12c14445209c3b341ed85f5f Mon Sep 17 00:00:00 2001 From: schneems Date: Wed, 10 Feb 2021 09:58:50 -0600 Subject: [PATCH 2/2] Fix Ruby 2.5 and 2.6 error detection Apparently depending on the sub version of Ruby 2.6 and the specific syntax, the error may or may not include the comma. Ruby 2.5 has different cases for `Unexpected end` and `unexpected end`. --- lib/dead_end/who_dis_syntax_error.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/dead_end/who_dis_syntax_error.rb b/lib/dead_end/who_dis_syntax_error.rb index 4f5e360..5d22cfe 100644 --- a/lib/dead_end/who_dis_syntax_error.rb +++ b/lib/dead_end/who_dis_syntax_error.rb @@ -45,19 +45,20 @@ def on_parse_error(msg) @error = msg @unmatched_symbol = :unknown - if @error.match?(/unexpected end-of-input/) + case @error + when /unexpected end-of-input/ @error_symbol = :missing_end - elsif @error.match?(/expecting end-of-input/) + when /expecting end-of-input/ @error_symbol = :unmatched_syntax @unmatched_symbol = :end - elsif @error.match?(/unexpected `end'/) || # Ruby 2.7 & 3.0 - @error.match?(/unexpected end,/) || # Ruby 2.6 - @error.match?(/unexpected keyword_end/) # Ruby 2.5 - - @error_symbol = :unmatched_syntax + when /unexpected `end'/, # Ruby 2.7 and 3.0 + /unexpected end/, # Ruby 2.6 + /unexpected keyword_end/i # Ruby 2.5 match = @error.match(/expecting '(?.*)'/) @unmatched_symbol = match[:unmatched_symbol].to_sym if match + + @error_symbol = :unmatched_syntax else @error_symbol = :unknown end