sqlint 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca4703618f9528f3c18388c9b4942b4ff527b73e
4
- data.tar.gz: f56f97f3498168c72e3265b9a2d9af8c01f28b8d
3
+ metadata.gz: 2a659c0622ca330e784dfecef69f5c0545f79836
4
+ data.tar.gz: 14ad1e500274a2b00a98cb20ea3f58fe2eb2c5a4
5
5
  SHA512:
6
- metadata.gz: 440303275dca244c8c3d60458b5abe26fe524894663eb3557cb90350e9c41116bf55fd82b2ce43902f2fa1248aeaae32de91f406bac4fdce87a6c2614fafc946
7
- data.tar.gz: 8f46e7850cd670876e9605233f90cbbf81158e44e48f7bcac4d39c7b114158a36bed810c75ddc5dbeebcb752110cf9b18ff64977bb3ebd225dadda95eb899efe
6
+ metadata.gz: 52bfbfbfc45980d7398932b0098f152bd1e8ffa0a55e0acfa09480634553b58c0d63cbdd3490883b48ba4aa7202bee65252e0ff6cb7121e951d92183b3f8fb03
7
+ data.tar.gz: 8f30c0e45b775eafd0e062e655d2d8bfba4fe2002049c7c6e7ced55da7581a8adf63cc58801eab91f7a97083299bb00e30b78ab32649574a808abc272cd1f501
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- [![Build Status](https://travis-ci.org/purcell/sqlint.png?branch=master)](https://travis-ci.org/purcell/sqlint)
1
+ [![Build Status](https://travis-ci.org/purcell/sqlint.svg?branch=master)](https://travis-ci.org/purcell/sqlint)
2
+ [ ![](https://img.shields.io/gem/v/sqlint.svg)](https://rubygems.org/gems/sqlint)
3
+ [ ![](https://img.shields.io/gem/dt/sqlint.svg)](https://rubygems.org/gems/sqlint)
2
4
 
3
5
  ## SQLint - a simple SQL linter
4
6
 
data/TODO ADDED
@@ -0,0 +1,9 @@
1
+ - [-] More input test cases?
2
+ - [-] Handle any warnings returned by PgQuery.parse
3
+ - [X] Limit number of warnings
4
+ - [ ] Optionally connect to a live DB to check referenced table/column names are valid
5
+ - [ ] Refactor and test the CLI front end
6
+ - [ ] Support for other SQL dialects
7
+ - [ ] JSON output
8
+ - [ ] Huge files
9
+ - [X] Maybe truncate long 'at or near "blah"' strings
data/bin/sqlint CHANGED
@@ -1,22 +1,33 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # What if 1000+ errors => --limit
4
- # Split on "; -- ..."
5
-
6
-
7
-
8
3
  $LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
9
4
  require 'pg_query'
10
5
  require 'sqlint'
6
+ require 'optparse'
11
7
 
12
- if ARGV.include?("--version")
13
- puts SQLint::VERSION
14
- exit 0
15
- end
8
+ LIMIT = 1000
16
9
 
17
- if ARGV.empty? || ARGV.include?("--help") || ARGV.include?("-h")
18
- puts "Usage: sqlint file.sql ..."
19
- exit 0
10
+ options = { limit: 1000 }
11
+ optparse = OptionParser.new do |opts|
12
+ opts.banner = "Usage: #{File.basename($0)} [options] file.sql ..."
13
+ opts.separator ""
14
+ opts.separator "Options:"
15
+ opts.on("--limit=N", Integer, "Limit checking to N errors") do |n|
16
+ options[:limit] = n
17
+ end
18
+ opts.on_tail("-h", "--help", "Print this help") do
19
+ puts opts
20
+ exit 0
21
+ end
22
+ opts.on_tail("-v", "--version", "Display the version") do
23
+ puts SQLint::VERSION
24
+ exit 0
25
+ end
26
+ end
27
+ optparse.parse!(ARGV)
28
+ if ARGV.empty?
29
+ puts optparse
30
+ exit 1
20
31
  end
21
32
 
22
33
  ERROR_TYPES = {error: "ERROR", warning: "WARNING"}
@@ -32,7 +43,7 @@ end
32
43
  saw_errors = false
33
44
  ARGV.each do |filename|
34
45
  File.open(filename, 'r') do |file|
35
- results = SQLint::Linter.new(filename, file).run
46
+ results = SQLint::Linter.new(filename, file).run.first(options[:limit])
36
47
  results.each do |lint|
37
48
  message_lines = lint.message.split("\n")
38
49
  puts [
@@ -12,7 +12,7 @@ module SQLint
12
12
  end
13
13
 
14
14
  def run
15
- [].tap do |results|
15
+ Enumerator.new do |results|
16
16
  state = ParseState.new(@input, 0)
17
17
  while state != END_PARSE
18
18
  error, new_parse_state = parse_next_error(state)
@@ -31,7 +31,7 @@ module SQLint
31
31
  rescue PgQuery::ParseError => e
32
32
  offset = e.location + parse_state.offset
33
33
  line_number, column_number = find_absolute_position(offset)
34
- lint = Lint.new(@filename, line_number, column_number, :error, e.message)
34
+ lint = Lint.new(@filename, line_number, column_number, :error, clean_message(e.message))
35
35
 
36
36
  input_from_error = parse_state.input[e.location..-1]
37
37
  semicolon_pos = input_from_error.index(";") if input_from_error
@@ -54,5 +54,9 @@ module SQLint
54
54
  column_number = lines_before_error.any? ? lines_before_error.last.size : 1
55
55
  [line_number, column_number]
56
56
  end
57
+
58
+ def clean_message(message)
59
+ message.gsub(/(?<=at or near ")(.*)(?=")/) { |match| match[0..49] }
60
+ end
57
61
  end
58
62
  end
@@ -1,3 +1,3 @@
1
1
  module SQLint
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Purcell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-16 00:00:00.000000000 Z
12
+ date: 2015-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg_query
@@ -80,6 +80,7 @@ files:
80
80
  - Gemfile.lock
81
81
  - LICENSE.txt
82
82
  - README.md
83
+ - TODO
83
84
  - bin/sqlint
84
85
  - lib/sqlint.rb
85
86
  - lib/sqlint/linter.rb