dense-analysis / dense-analysis/ale
Add support for Common Lisp with sblint
- Dominant language
- Vim Script
- Stars
- 14k
- Forks
- 1.5k
- Avg merge
- 17h 49m
- Merged PRs (30d)
- 1
Description
**Name:** sblint
**URL:** https://github.com/cxxxr/sblint
I took a crack at adding support locally and (barring the double regex since my regex-fu is weak today) this seems to work ok-enough.
```vim
"ale_linters/lisp/sblint.vim
function! ale_linters#lisp#sblint#Handle(buffer, lines) abort
" General format is
" ::: :
" Examples:
"src/font.lisp:11:39: compiler-error: READ error during COMPILE-FILE: Package SDL2-TF does not exist. Line: 11, Column: 40, File-Position: 307 Stream: #
"src/font.lisp:8:0: style-warning: The variable A is defined but never used.
"
" compiler-error errors have all that extra redundant junk that shouldn't
" be part of the description.
let l:pattern_compiler = '^\(.\+\):\(\d\+\):\(\d\+\): \(compiler-error\): \(.\+\) Line: \(\d\+\), Column: \(\d\+\)\(.\+\)$'
let l:pattern = '^\(.\+\):\(\d\+\):\(\d\+\): \(compiler-error\)\@!\(.\+\): \(.\+\)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern_compiler)
call add(l:output, {
\ 'filename': l:match[1],
\ 'lnum': l:match[2] + 0,
\ 'col': l:match[3] + 0,
\ 'type': l:match[4],
\ 'text': l:match[5],
\})
endfor
for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:output, {
\ 'filename': l:match[1],
\ 'lnum': l:match[2] + 0,
\ 'col': l:match[3] + 0,
\ 'type': l:match[5],
\ 'text': l:match[6],
\})
endfor
return l:output
endfunction
call ale#linter#Define('lisp', {
\ 'name': 'sblint',
\ 'executable': 'sblint',
\ 'command': 'sblint',
\ 'callback': 'ale_linters#lisp#sblint#Handle',
\})
```
It takes advantage of the fact that sblint with no arguments will look in the current directory for any .asd files (typically projects have at least one specifying the project's set of Lisp files) and compile them for linting. I make use of [rooter](https://github.com/airblade/vim-rooter) so this works for me even if my lisp files are nested in src/ and my asd file is above that. To make this more robust I think it should try to detect the project root and pass that directory name as a single argument.
While sblint can work on single files it's really meant for whole-project analysis, and ignores stdin so that linting only updates on file save. Perhaps a future improvement to sblint could be to give it an additional parameter specifying a replacement filename (i.e. the active buffer that ALE normally passes over stdin from somewhere in /tmp/) that it can check if it overlaps with a project file inside the asd definition. Or if there is no overlap like in the case of a new file, compile and lint the new file after having done so for the other files listed in the asd.
Contributor guide
Assessment
This issue has not been assessed yet.