sqlint 0.1.0 → 0.1.1
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 +3 -1
 - data/TODO +9 -0
 - data/bin/sqlint +24 -13
 - data/lib/sqlint/linter.rb +6 -2
 - data/lib/sqlint/version.rb +1 -1
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 2a659c0622ca330e784dfecef69f5c0545f79836
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 14ad1e500274a2b00a98cb20ea3f58fe2eb2c5a4
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 52bfbfbfc45980d7398932b0098f152bd1e8ffa0a55e0acfa09480634553b58c0d63cbdd3490883b48ba4aa7202bee65252e0ff6cb7121e951d92183b3f8fb03
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 8f30c0e45b775eafd0e062e655d2d8bfba4fe2002049c7c6e7ced55da7581a8adf63cc58801eab91f7a97083299bb00e30b78ab32649574a808abc272cd1f501
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,4 +1,6 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            [](https://travis-ci.org/purcell/sqlint)
         
     | 
| 
      
 2 
     | 
    
         
            +
            [ ](https://rubygems.org/gems/sqlint)
         
     | 
| 
      
 3 
     | 
    
         
            +
            [ ](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 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
              puts SQLint::VERSION
         
     | 
| 
       14 
     | 
    
         
            -
              exit 0
         
     | 
| 
       15 
     | 
    
         
            -
            end
         
     | 
| 
      
 8 
     | 
    
         
            +
            LIMIT = 1000
         
     | 
| 
       16 
9 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
               
     | 
| 
      
 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 [
         
     | 
    
        data/lib/sqlint/linter.rb
    CHANGED
    
    | 
         @@ -12,7 +12,7 @@ module SQLint 
     | 
|
| 
       12 
12 
     | 
    
         
             
                end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                def run
         
     | 
| 
       15 
     | 
    
         
            -
                   
     | 
| 
      
 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
         
     | 
    
        data/lib/sqlint/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 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
         
     |