Files
ale/ale_linters/html/djlint.vim
Vivian De Smedt 3611c32d60
Some checks failed
CI / build_image (push) Has been cancelled
CI / test_ale (--linters-only) (push) Has been cancelled
CI / test_ale (--neovim-06-only) (push) Has been cancelled
CI / test_ale (--neovim-08-only) (push) Has been cancelled
CI / test_ale (--vim-80-only) (push) Has been cancelled
CI / test_ale (--vim-90-only) (push) Has been cancelled
Add support for the [djlinter](https://www.djlint.com/) (#4909)
* Add support for the [djlinter](https://www.djlint.com/)

* Add documentation and tests.

* Fix the name of the variable for the executable name.

* Correct the name of the handler in the test.

* Correct the test adding the value of vcol.

* Format djlint.vim according to formatting rules.
2025-03-08 16:45:17 +09:00

49 lines
1.4 KiB
VimL

" Author: Vivian De Smedt <vds2212@gmail.com>
" Description: Adds support for djlint
call ale#Set('html_djlint_executable', 'djlint')
call ale#Set('html_djlint_options', '')
function! ale_linters#html#djlint#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'html_djlint_executable')
endfunction
function! ale_linters#html#djlint#GetCommand(buffer) abort
let l:executable = ale_linters#html#djlint#GetExecutable(a:buffer)
let l:options = ale#Var(a:buffer, 'html_djlint_options')
return ale#Escape(l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '') . ' %s'
endfunction
function! ale_linters#html#djlint#Handle(buffer, lines) abort
let l:output = []
let l:pattern = '\v^([A-Z]\d+) (\d+):(\d+) (.*)$'
let l:i = 0
for l:match in ale#util#GetMatches(a:lines, l:pattern)
let l:i += 1
let l:item = {
\ 'lnum': l:match[2] + 0,
\ 'col': l:match[3] + 0,
\ 'vcol': 1,
\ 'text': l:match[4],
\ 'code': l:match[1],
\ 'type': 'W',
\}
call add(l:output, l:item)
endfor
return l:output
endfunction
call ale#linter#Define('html', {
\ 'name': 'djlint',
\ 'executable': function('ale_linters#html#djlint#GetExecutable'),
\ 'command': function('ale_linters#html#djlint#GetCommand'),
\ 'callback': 'ale_linters#html#djlint#Handle',
\})
" vim:ts=4:sw=4:et: