From 3a01509ae5cf4db85c8035c4b105334301a2bd5a Mon Sep 17 00:00:00 2001
From: Kieran Trezona-le Comte <trezona-lecomte@gmail.com>
Date: Fri, 17 Jul 2015 11:05:44 +1200
Subject: [PATCH] Handle subsequent error at end of input

---
 lib/sqlint/linter.rb | 2 +-
 spec/sqlint_spec.rb  | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/sqlint/linter.rb b/lib/sqlint/linter.rb
index 87f254f..262a906 100644
--- a/lib/sqlint/linter.rb
+++ b/lib/sqlint/linter.rb
@@ -34,7 +34,7 @@ module SQLint
         lint = Lint.new(@filename, line_number, column_number, :error, e.message)
 
         input_from_error = parse_state.input[e.location..-1]
-        semicolon_pos = input_from_error.index(";")
+        semicolon_pos = input_from_error.index(";") if input_from_error
         [
           lint,
           if semicolon_pos
diff --git a/spec/sqlint_spec.rb b/spec/sqlint_spec.rb
index 8bd50af..3ffe696 100644
--- a/spec/sqlint_spec.rb
+++ b/spec/sqlint_spec.rb
@@ -62,5 +62,13 @@ RSpec.describe SQLint do
         expect(results).to eq([error(1, 1, WIBBLE_ERROR), error(1, 9, WIBBLE_ERROR)])
       end
     end
+
+    context "when there is a second error at the end of the file" do
+      let(:input) { "WIBBLE; SELECT 1 FROM" }
+      it "report 2 errors" do
+        expect(results).to eq([error(1, 1, WIBBLE_ERROR),
+                               error(1, 21, "syntax error at end of input")])
+      end
+    end
   end
 end
-- 
GitLab