diff --git a/ale_linters/jinja/j2lint.vim b/ale_linters/jinja/j2lint.vim new file mode 100644 index 00000000..ed024468 --- /dev/null +++ b/ale_linters/jinja/j2lint.vim @@ -0,0 +1,46 @@ +" Description: linter for jinja using j2lint + +call ale#Set('jinja_j2lint_executable', 'j2lint') +call ale#Set('jinja_j2lint_options', '') +call ale#Set('jinja_j2lint_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('jinja_j2lint_auto_pipenv', 0) +call ale#Set('jinja_j2lint_auto_poetry', 0) +call ale#Set('jinja_j2lint_auto_uv', 0) + +function! ale_linters#jinja#j2lint#GetExecutable(buffer) abort + if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'jinja_j2lint_auto_pipenv')) + \ && ale#python#PipenvPresent(a:buffer) + return 'pipenv' + endif + + if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'jinja_j2lint_auto_poetry')) + \ && ale#python#PoetryPresent(a:buffer) + return 'poetry' + endif + + if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'jinja_j2lint_auto_uv')) + \ && ale#python#UvPresent(a:buffer) + return 'uv' + endif + + return ale#python#FindExecutable(a:buffer, 'jinja_j2lint', ['j2lint']) +endfunction + +function! ale_linters#jinja#j2lint#GetCommand(buffer) abort + let l:executable = ale_linters#jinja#j2lint#GetExecutable(a:buffer) + + let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$' + \ ? ' run j2lint' + \ : '' + + return ale#Escape(l:executable) . l:exec_args + \ . ale#Pad(ale#Var(a:buffer, 'jinja_j2lint_options')) + \ . ' %t' +endfunction + +call ale#linter#Define('jinja', { +\ 'name': 'j2lint', +\ 'executable': function('ale_linters#jinja#j2lint#GetExecutable'), +\ 'command': function('ale_linters#jinja#j2lint#GetCommand'), +\ 'callback': 'ale#handlers#unix#HandleAsError', +\}) diff --git a/doc/ale-jinja.txt b/doc/ale-jinja.txt index 37769fe9..ad01d22d 100644 --- a/doc/ale-jinja.txt +++ b/doc/ale-jinja.txt @@ -8,5 +8,9 @@ djlint *ale-jinja-djlint* See |ale-html-djlint| +=============================================================================== +j2lint *ale-jinja-j2lint* + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 880527a1..56f0a211 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -336,6 +336,7 @@ Notes: * `xo` * Jinja * djlint + * j2lint * JSON * `VSCode JSON language server` * `biome` diff --git a/doc/ale.txt b/doc/ale.txt index 5d7b1254..07f56d28 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3634,6 +3634,7 @@ documented in additional help files. xo....................................|ale-javascript-xo| jinja...................................|ale-jinja-options| djlint................................|ale-jinja-djlint| + j2lint................................|ale-jinja-j2lint| json....................................|ale-json-options| biome.................................|ale-json-biome| clang-format..........................|ale-json-clangformat| diff --git a/supported-tools.md b/supported-tools.md index a89b9230..fdd611ba 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -346,6 +346,7 @@ formatting. * [xo](https://github.com/sindresorhus/xo) * Jinja * [djlint](https://djlint.com/) + * [j2lint](https://github.com/aristanetworks/j2lint/) * JSON * [VSCode JSON language server](https://github.com/hrsh7th/vscode-langservers-extracted) * [biome](https://biomejs.dev/) diff --git a/test/linter/test_j2lint.vader b/test/linter/test_j2lint.vader new file mode 100644 index 00000000..74b82f7d --- /dev/null +++ b/test/linter/test_j2lint.vader @@ -0,0 +1,44 @@ +Before: + call ale#assert#SetUpLinterTest('jinja', 'j2lint') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The j2lint executable should be configurable): + let g:ale_jinja_j2lint_executable = '~/.local/bin/j2lint' + + AssertLinter '~/.local/bin/j2lint', + \ ale#Escape('~/.local/bin/j2lint'). ' %t' + +Execute(Setting executable to 'pipenv' appends 'run j2lint'): + let g:ale_jinja_j2lint_executable = 'path/to/pipenv' + + AssertLinter 'path/to/pipenv', + \ ale#Escape('path/to/pipenv') . ' run j2lint %t' + +Execute(Pipenv is detected when jinja_j2lint_auto_pipenv is set): + let g:ale_jinja_j2lint_auto_pipenv = 1 + call ale#test#SetFilename('../test-files/python/pipenv/whatever.py') + + AssertLinter 'pipenv', + \ ale#Escape('pipenv') . ' run j2lint %t' + +Execute(Setting executable to 'poetry' appends 'run j2lint'): + let g:ale_jinja_j2lint_executable = 'path/to/poetry' + + AssertLinter 'path/to/poetry', + \ ale#Escape('path/to/poetry') . ' run j2lint %t' + +Execute(Poetry is detected when jinja_j2lint_auto_poetry is set): + let g:ale_jinja_j2lint_auto_poetry = 1 + call ale#test#SetFilename('../test-files/python/poetry/whatever.py') + + AssertLinter 'poetry', + \ ale#Escape('poetry') . ' run j2lint %t' + +Execute(uv is detected when jinja_j2lint_auto_uv is set): + let g:ale_jinja_j2lint_auto_uv = 1 + call ale#test#SetFilename('../test-files/python/uv/whatever.py') + + AssertLinter 'uv', + \ ale#Escape('uv') . ' run j2lint %t'