Open joereynolds opened 6 years ago
Ale patch
" ale_linters/sql/sqllint.vim
" Author: Joe Reynolds <joereynolds952@gmail.com>
" Description: sql-lint for SQL files
function! ale_linters#sql#sqllint#Handle(buffer, lines) abort
" Matches patterns like the following:
"
" stdin:1 [ER_NO_DB_ERROR] No database selected
let l:pattern = '\v^[^:]+:(\d+) (.*)'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
" echom l:match[0]
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'type': l:match[3][0],
\ 'text': l:match[0],
\})
endfor
return l:output
endfunction
call ale#linter#Define('sql', {
\ 'name': 'sqllint',
\ 'executable': 'sql-lint',
\ 'command': 'sql-lint',
\ 'callback': 'ale_linters#sql#sqllint#Handle',
\})
It'd be nice to get support added into ALE directly so that it automatically uses sql-lint if it's installed. I'll take a look at past PRs in w0rp/ALE to add linters and see if it's something I can knock out.
EDIT: Oops, looks like it is already here https://github.com/w0rp/ale/pull/2221
Hey @andrewimeson you're welcome to take a stab at it, I doubt I'll get around to finishing it off any time soon
As an update, I've opened up a new PR on the ale repo here:
Hey @andrewimeson
My patch has been merged into ale. Enjoy!
It'd be good if vim users could just have this installed locally and not as a global dependency. See #170
How it should work
sql
ftplugin which should contain the followingvim-plug
it should look like this:This will do
npm install sql-lint
under the hood.A nice to have is that it would work in non
.sql
files.i.e. for PHP, it should try its best to recognise an SQL query in the buffer and run sql-lint on that query.