Add support for the [djlinter](https://www.djlint.com/) (#4909)
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/)

* 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.
This commit is contained in:
Vivian De Smedt
2025-03-08 08:45:17 +01:00
committed by GitHub
parent a6db6c95a6
commit 3611c32d60
7 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
" 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:

View File

@@ -33,6 +33,25 @@ cspell *ale-html-cspell*
See |ale-cspell-options|
===============================================================================
djlint *ale-html-djlint*
g:ale_html_djlint_executable *g:ale_html_djlint_executable*
*b:ale_html_djlint_executable*
Type: |String|
Default: `'djlint'`
See |ale-integrations-local-executables|
g:ale_html_djlint_options *g:ale_html_djlint_options*
*b:ale_html_djlint_options*
Type: |String|
Default: `''`
This variable can be changed to modify flags given to djlint.
===============================================================================
fecs *ale-html-fecs*

View File

@@ -274,6 +274,7 @@ Notes:
* `alex`
* `angular`
* `cspell`
* djlint
* `eslint`
* `fecs`
* `html-beautify`

View File

@@ -3106,6 +3106,7 @@ documented in additional help files.
html....................................|ale-html-options|
angular...............................|ale-html-angular|
cspell................................|ale-html-cspell|
djlint................................|ale-html-djlint|
fecs..................................|ale-html-fecs|
html-beautify.........................|ale-html-beautify|
htmlhint..............................|ale-html-htmlhint|

View File

@@ -283,6 +283,7 @@ formatting.
* [alex](https://github.com/get-alex/alex)
* [angular](https://www.npmjs.com/package/@angular/language-server)
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
* [djlint](https://www.djlint.com/)
* [eslint](https://github.com/BenoitZugmeyer/eslint-plugin-html)
* [fecs](http://fecs.baidu.com/)
* [html-beautify](https://beautifier.io/)

View File

@@ -0,0 +1,21 @@
Before:
runtime ale_linters/html/djlint.vim
After:
call ale#linter#Reset()
Execute(The Djlint handler should parse output with a column correctly):
AssertEqual
\ [
\ {
\ 'lnum': 47,
\ 'vcol': 1,
\ 'col': 8,
\ 'code': 'H008',
\ 'text': 'Attributes should be double quoted.',
\ 'type': 'W'
\ }
\ ],
\ ale_linters#html#djlint#Handle(0, [
\ 'H008 47:8 Attributes should be double quoted.'
\ ])

View File

@@ -0,0 +1,14 @@
Before:
call ale#assert#SetUpLinterTest('html', 'djlint')
After:
call ale#assert#TearDownLinterTest()
Execute(The default djlint command should be correct):
AssertLinter 'djlint', ale#Escape('djlint') . ' %s'
Execute(The executable should be configurable):
let g:ale_html_djlint_executable = 'foo bar'
let g:ale_html_djlint_options = '--option'
AssertLinter 'foo bar', ale#Escape('foo bar') . ' --option %s'