Skip to content

Latest commit

 

History

History
32 lines (27 loc) · 1.1 KB

README.md

File metadata and controls

32 lines (27 loc) · 1.1 KB

gsl

go-sql-linter | good-sql-looks

Dev

# build
$ go build -o gsl main.go
# test
$ gsl lint example/test.sql

TODOs

cmd

  • error if filename not .sql
  • overwrite previous file
  • take multiple files could be gsl file1 file2 or gsl . with an -r flag for recursive

lint rules

  • Trailing Whitespace
  • Greater than one newline
  • capitalisation of SQL keywords
    • Bug: doesn't work if keyword has delimiter , immediately before/after keyword
    • Bug: doesn't work if keyword is a function e.g. if(a...
  • detecting nested queries
  • 2 spaces for indentation. Not tabs.
  • blank line between groups of logic e.g after a select statement, after a from, after Joins etc

Optimisations

  • each lint rule/function loops through lines of the .sql file. Whilst this is O(N), once there are a many of rules e.g. 10 the speed could noticeably be increased
  • the in-memory impact of a sql file or several variants is likely very small, however optimisation using pointers could make this even more light weight.