• Stars
    star
    435
  • Rank 100,085 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An SQL linter

sql-lint

sql-lint will do sanity checks on your queries as well as bring errors back from the DB. If you worry about forgetting WHEREs on a DELETE or borking your data with unexpected characters, then sql-lint is for you.

Read the documentation for a complete walkthrough

Imgur

Imgur

Installation

npm i -g sql-lint
# or
yarn global add sql-lint

Or download a binary

Usage

sql-lint works on files, directories and stdin.

# Will lint all .sql files recursively from the current directory
sql-lint .

# Lints the create-person.sql file
sql-lint create-person.sql

# Lints stdin
echo 'DELETE FROM person;' | sql-lint

Programmatically

sql-lint can also be used within your js/ts files (though admittedly it's stronger as a cli command).

npm i sql-lint
# or
yarn add sql-lint
import sqlLint from 'sql-lint'

// using async/await

const errors = await sqlLint({
  sql: 'SELECT my_column FROM my_table',
})

// or using promise

sqlLint({ sql: 'SELECT my_column FROM my_table' }).then(errors => {
  for (const error of errors) {
    // do something
  }
})

Supported Editors

If your editor supports external tools, then it supports sql-lint. Below is the list that have direct support for sql-lint either through plugins or configuration.

Editor Plugin
Neovim Ale
Vim Ale
VS Code Inline SQL

Checks

A quick rundown of the checks is below but you should read the documentation for an exhaustive list.

sql-lint comes with its own suite of checks. It also returns any errors from the SQL server you have connected to. Generally you'll find that the errors from sql-lint are more informative than those from the server. That said, you will still want errors from the server as it covers more cases and will catch things that sql-lint does not.

unmatched-parentheses

Shown when a query has an unbalanced amount of parentheses.

test/test-files//test.sql:16 [sql-lint: unmatched-parentheses] Unmatched parentheses.
missing-where

Shown when a DELETE statement is missing a WHERE clause.

test/test-files/test.sql:20 [sql-lint: missing-where] DELETE statement missing WHERE clause.
invalid-drop-option

Shown when an invalid option is given to the DROP statement.

test/test-files/test.sql:22 [sql-lint: invalid-drop-option] Option 'thing' is not a valid option, must be one of '["database","event","function","index","logfile","procedure","schema","server","table","view","tablespace","trigger"]'.
invalid-create-option

Shown when an invalid option is given to the CREATE statement.

:24 [sql-lint: invalid-create-option] Option 'test' is not a valid option, must be one of '["algorithm","database","definer","event","function","index","or","procedure","server","table","tablespace","temporary","trigger","user","unique","view"]'.
invalid-truncate-option

Shown when an invalid option is given to the TRUNCATE statement.

test/test-files/test.sql:26 [sql-lint: invalid-truncate-option] Option 'something' is not a valid option, must be one of '["table"]'.
invalid-alter-option

Shown when an invalid option is given to the ALTER statement.

test/test-files/test.sql:28 [sql-lint: invalid-alter-option] Option 'mlady' is not a valid option, must be one of '["column","online","offline","ignore","database","event","function","procedure","server","table","tablespace","view"]'.
odd-code-point

Shown when there are unsupported/unusual* code points in your code.

*This check came about whilst working Microsoft Excel. Microsoft likes to add a lot of zany characters which can subtly break your data without you realising.

test/test-files//test.sql:30 [sql-lint: odd-code-point] Unexpected code point.
invalid-limit-quantifier

Shown when you specify something other than a number to the LIMIT statement.

test/test-files//test.sql:32 [sql-lint: invalid-limit-quantifier] Argument 'test' is not a valid quantifier for LIMIT clause.
hungarian-notation

Shown when the string sp_ or tbl_ is present in the query.

test/test-files/test.sql:34 [sql-lint: hungarian-notation] Hungarian notation present in query
trailing-whitespace

Shown when a query has trailing whitespace.

test/test-files/test.sql:34 [sql-lint: trailing-whitespace] Trailing whitespace

Documentation

To find out more, read the documentation

More Repositories

1

what-to-code

Ideas for things to program
1,363
star
2

SQHell.vim

An SQL wrapper for vim
Vim Script
132
star
3

mort

Dead CSS detection
TypeScript
118
star
4

fanbox

A HTML + CSS + JS desktop dashboard!
HTML
94
star
5

place.vim

Enter pieces of text without moving
Vim Script
43
star
6

reap-get

A package manager for VST plugins!
Python
36
star
7

cmaj

Music theory from the command line
Python
36
star
8

Image-to-Ascii

An image to Ascii converter written in Python
23
star
9

AsciiThis-Bot

The code for the AsciiThis bot on Reddit
C#
17
star
10

exoskeleton.vim

Skeleton vim improved
Vim Script
17
star
11

haxe-heaps-examples

Simple demonstrations of doing things with Heaps
Haxe
16
star
12

configs

My dotfiles and configs
Shell
15
star
13

gtags-scope

An up-to-date version of gtags-cscope.vim from GNU global
Vim Script
15
star
14

life

A dump of my docs
Shell
13
star
15

metronome

The metronome on
JavaScript
12
star
16

deoplete-minisnip

Deoplete source for vim-minisnip
Python
12
star
17

entree

A wrapper for entr that allows you to version control your watchers
Shell
10
star
18

silver-doodle

A linter for the Scheme programming language
Python
9
star
19

gq.vim

formatprgs for many filetypes
Vim Script
6
star
20

vim-c-manual

Vim :help for the C11 standard
Python
6
star
21

pcre-vim

Convert PCREs to vim expressions
Lua
4
star
22

css-refactoring-patterns

Refactoring patterns for CSS
HTML
4
star
23

salutem

Health checking for frugal server administrators
Python
4
star
24

what

Get help for cli flags instantly
Lua
2
star
25

joereynolds.github.io

The source for
Ruby
1
star
26

programming-dump

A dump of programming stuff. Challenges, algorithms, data structures etc...
C
1
star
27

mr-grabby

Read websites from the command line
Shell
1
star
28

mrfigsgame.com

The Website for Mr Figs
HTML
1
star
29

all-skate-decks

A website commemorating all skateboard decks from the past (and present)
JavaScript
1
star
30

this-isnt-tennis

A top down action game
Lua
1
star