diff --git a/lib/sqlint/linter.rb b/lib/sqlint/linter.rb index 87f254f0b305573842ae255edb9b45d147a4f7f1..262a9069d57a25b1b57893746726f811062a14d2 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 8bd50af96838f28aea19e60ccebc61631553dd15..3ffe6960c8f843e409dacee24f456d70b67d3dd4 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