sqlint 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8299d22b3799957a801442f25ecf60c1d3538f3
4
- data.tar.gz: 7e9564d42eda301285008931947e05cecd399faf
3
+ metadata.gz: ca4703618f9528f3c18388c9b4942b4ff527b73e
4
+ data.tar.gz: f56f97f3498168c72e3265b9a2d9af8c01f28b8d
5
5
  SHA512:
6
- metadata.gz: 6aaddf95c7506f3b00e436d888d9e11244e410b55947597b14e3ed56c08fea4ffae2f8edf25742cf51736389be24adc9f46286b6c5b918f779106618aa6acdfb
7
- data.tar.gz: c6e5b3086494649f56859029f111ada4e58fee9588a425c3c11dd27d30891be230b5a1ade6ff9cac871d5176eb4a7fc1d141d280e46d0e1324dfcf4e278d71f5
6
+ metadata.gz: 440303275dca244c8c3d60458b5abe26fe524894663eb3557cb90350e9c41116bf55fd82b2ce43902f2fa1248aeaae32de91f406bac4fdce87a6c2614fafc946
7
+ data.tar.gz: 8f46e7850cd670876e9605233f90cbbf81158e44e48f7bcac4d39c7b114158a36bed810c75ddc5dbeebcb752110cf9b18ff64977bb3ebd225dadda95eb899efe
data/README.md CHANGED
@@ -31,15 +31,18 @@ sqlint filename.sql
31
31
 
32
32
  Support for `sqlint` is provided for the following editors:
33
33
 
34
- - Emacs, via Flycheck ([submission pending](https://github.com/flycheck/flycheck/pull/691))
35
- - VIM, via Syntastic ([submission pending](https://github.com/scrooloose/syntastic/pull/1477))
34
+ - Emacs, via [Flycheck](https://github.com/flycheck/flycheck)
35
+ - VIM, via [Syntastic](https://github.com/scrooloose/syntastic)
36
36
  - SublimeText, via the SublimeLinter package ([submission pending](https://github.com/SublimeLinter/SublimeLinter3/issues/297))
37
37
 
38
38
  ### Authors
39
39
 
40
- This software was written by Steve Purcell and Kieran Trezona-le Comte
41
- with the support of our awesome employer
42
- [Powershop](http://www.powershop.co.nz/).
40
+ This software was written by
41
+ [Steve Purcell](https://github.com/purcell) and
42
+ [Kieran Trezona-le Comte](https://github.com/trezona-lecomte) with the
43
+ support of our awesome employer
44
+ [Powershop](http://www.powershop.co.nz/), who have other cool stuff
45
+ [here on Github](https://github.com/powershop).
43
46
 
44
47
  ### License and copyright
45
48
 
@@ -3,6 +3,8 @@ require 'pg_query'
3
3
  module SQLint
4
4
  class Linter
5
5
  Lint = Struct.new(:filename, :line, :column, :type, :message)
6
+ ParseState = Struct.new(:input, :offset)
7
+ END_PARSE = ParseState.new(nil, nil)
6
8
 
7
9
  def initialize(filename, input_stream)
8
10
  @input = input_stream.read
@@ -11,16 +13,46 @@ module SQLint
11
13
 
12
14
  def run
13
15
  [].tap do |results|
14
- begin
15
- PgQuery.parse(@input)
16
- rescue PgQuery::ParseError => e
17
- offset = e.location
18
- lines_before_error = @input[0...(offset)].split("\n")
19
- line_number = lines_before_error.size
20
- column_number = lines_before_error.any? ? lines_before_error.last.size : 1
21
- results << Lint.new(@filename, line_number, column_number, :error, e.message)
16
+ state = ParseState.new(@input, 0)
17
+ while state != END_PARSE
18
+ error, new_parse_state = parse_next_error(state)
19
+ results << error if error
20
+ state = new_parse_state
22
21
  end
23
22
  end
24
23
  end
24
+
25
+ private
26
+
27
+ def parse_next_error(parse_state)
28
+ begin
29
+ PgQuery.parse(parse_state.input)
30
+ [nil, END_PARSE]
31
+ rescue PgQuery::ParseError => e
32
+ offset = e.location + parse_state.offset
33
+ line_number, column_number = find_absolute_position(offset)
34
+ lint = Lint.new(@filename, line_number, column_number, :error, e.message)
35
+
36
+ input_from_error = parse_state.input[e.location..-1]
37
+ semicolon_pos = input_from_error.index(";") if input_from_error
38
+ [
39
+ lint,
40
+ if semicolon_pos
41
+ remaining_input = input_from_error[semicolon_pos+1..-1]
42
+ new_offset = offset + semicolon_pos + 1
43
+ ParseState.new(remaining_input, new_offset)
44
+ else
45
+ END_PARSE
46
+ end
47
+ ]
48
+ end
49
+ end
50
+
51
+ def find_absolute_position(offset)
52
+ lines_before_error = @input[0...(offset)].split("\n")
53
+ line_number = lines_before_error.size
54
+ column_number = lines_before_error.any? ? lines_before_error.last.size : 1
55
+ [line_number, column_number]
56
+ end
25
57
  end
26
58
  end
@@ -1,3 +1,3 @@
1
1
  module SQLint
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Purcell