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 +4 -4
- data/README.md +8 -5
- data/lib/sqlint/linter.rb +40 -8
- data/lib/sqlint/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca4703618f9528f3c18388c9b4942b4ff527b73e
|
4
|
+
data.tar.gz: f56f97f3498168c72e3265b9a2d9af8c01f28b8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
35
|
-
- VIM, via Syntastic
|
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
|
41
|
-
|
42
|
-
[
|
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
|
|
data/lib/sqlint/linter.rb
CHANGED
@@ -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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
data/lib/sqlint/version.rb
CHANGED