I broke up with neovim....vim is my best friend now
This commit is contained in:
72
dot_vim/plugged/ale/ale_linters/sql/sqlfluff.vim
Normal file
72
dot_vim/plugged/ale/ale_linters/sql/sqlfluff.vim
Normal file
@@ -0,0 +1,72 @@
|
||||
" Author: Carl Smedstad <carl.smedstad at protonmail dot com>
|
||||
" Description: sqlfluff for SQL files
|
||||
|
||||
let g:ale_sql_sqlfluff_executable =
|
||||
\ get(g:, 'ale_sql_sqlfluff_executable', 'sqlfluff')
|
||||
|
||||
let g:ale_sql_sqlfluff_options =
|
||||
\ get(g:, 'ale_sql_sqlfluff_options', '')
|
||||
|
||||
function! ale_linters#sql#sqlfluff#Executable(buffer) abort
|
||||
return ale#Var(a:buffer, 'sql_sqlfluff_executable')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#sql#sqlfluff#Command(buffer) abort
|
||||
let l:executable = ale_linters#sql#sqlfluff#Executable(a:buffer)
|
||||
let l:options = ale#Var(a:buffer, 'sql_sqlfluff_options')
|
||||
|
||||
let l:cmd =
|
||||
\ ale#Escape(l:executable)
|
||||
\ . ' lint'
|
||||
|
||||
let l:config_file = ale#path#FindNearestFile(a:buffer, '.sqlfluff')
|
||||
|
||||
if !empty(l:config_file)
|
||||
let l:cmd .= ' --config ' . ale#Escape(l:config_file)
|
||||
else
|
||||
let l:cmd .= ' --dialect ansi'
|
||||
endif
|
||||
|
||||
let l:cmd .=
|
||||
\ ' --format json '
|
||||
\ . l:options
|
||||
\ . ' %t'
|
||||
|
||||
return l:cmd
|
||||
endfunction
|
||||
|
||||
function! ale_linters#sql#sqlfluff#Handle(buffer, lines) abort
|
||||
let l:output = []
|
||||
let l:json_lines = ale#util#FuzzyJSONDecode(a:lines, [])
|
||||
|
||||
if empty(l:json_lines)
|
||||
return l:output
|
||||
endif
|
||||
|
||||
let l:json = l:json_lines[0]
|
||||
|
||||
" if there's no warning, 'result' is `null`.
|
||||
if empty(get(l:json, 'violations'))
|
||||
return l:output
|
||||
endif
|
||||
|
||||
for l:violation in get(l:json, 'violations', [])
|
||||
call add(l:output, {
|
||||
\ 'filename': l:json.filepath,
|
||||
\ 'lnum': l:violation.line_no,
|
||||
\ 'col': l:violation.line_pos,
|
||||
\ 'text': l:violation.description,
|
||||
\ 'code': l:violation.code,
|
||||
\ 'type': 'W',
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('sql', {
|
||||
\ 'name': 'sqlfluff',
|
||||
\ 'executable': function('ale_linters#sql#sqlfluff#Executable'),
|
||||
\ 'command': function('ale_linters#sql#sqlfluff#Command'),
|
||||
\ 'callback': 'ale_linters#sql#sqlfluff#Handle',
|
||||
\})
|
||||
28
dot_vim/plugged/ale/ale_linters/sql/sqlint.vim
Normal file
28
dot_vim/plugged/ale/ale_linters/sql/sqlint.vim
Normal file
@@ -0,0 +1,28 @@
|
||||
" Author: Adriaan Zonnenberg <amz@adriaan.xyz>
|
||||
" Description: sqlint for SQL files
|
||||
|
||||
function! ale_linters#sql#sqlint#Handle(buffer, lines) abort
|
||||
" Matches patterns like the following:
|
||||
"
|
||||
" stdin:3:1:ERROR syntax error at or near "WIBBLE"
|
||||
let l:pattern = '\v^[^:]+:(\d+):(\d+):(\u+) (.*)'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:match[1] + 0,
|
||||
\ 'col': l:match[2] + 0,
|
||||
\ 'type': l:match[3][0],
|
||||
\ 'text': l:match[4],
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('sql', {
|
||||
\ 'name': 'sqlint',
|
||||
\ 'executable': 'sqlint',
|
||||
\ 'command': 'sqlint',
|
||||
\ 'callback': 'ale_linters#sql#sqlint#Handle',
|
||||
\})
|
||||
33
dot_vim/plugged/ale/ale_linters/sql/sqllint.vim
Normal file
33
dot_vim/plugged/ale/ale_linters/sql/sqllint.vim
Normal file
@@ -0,0 +1,33 @@
|
||||
" ale_linters/sql/sqllint.vim
|
||||
" Author: Joe Reynolds <joereynolds952@gmail.co>
|
||||
" Description: sql-lint for SQL files.
|
||||
" sql-lint can be found at
|
||||
" https://www.npmjs.com/package/sql-lint
|
||||
" https://github.com/joereynolds/sql-lint
|
||||
|
||||
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)
|
||||
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',
|
||||
\ 'aliases': ['sql-lint'],
|
||||
\ 'executable': 'sql-lint',
|
||||
\ 'command': 'sql-lint',
|
||||
\ 'callback': 'ale_linters#sql#sqllint#Handle',
|
||||
\})
|
||||
Reference in New Issue
Block a user