mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 12:44:23 +08:00
Compare commits
5 Commits
4217461c48
...
d2f4090c33
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2f4090c33 | ||
|
|
59c6b4f7b0 | ||
|
|
21d5de18b2 | ||
|
|
ed26d1f1d9 | ||
|
|
9811114948 |
46
ale_linters/jinja/j2lint.vim
Normal file
46
ale_linters/jinja/j2lint.vim
Normal file
@@ -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',
|
||||
\})
|
||||
@@ -27,6 +27,10 @@ function! ale_linters#php#phpstan#GetCommand(buffer, version) abort
|
||||
|
||||
let l:level = ale#Var(a:buffer, 'php_phpstan_level')
|
||||
|
||||
if type(l:level) is v:t_number
|
||||
let l:level = string(l:level)
|
||||
endif
|
||||
|
||||
if empty(l:level) && empty(ale_linters#php#phpstan#FindConfigFile(a:buffer))
|
||||
" if no configuration file is found, then use 4 as a default level
|
||||
let l:level = '4'
|
||||
@@ -83,6 +87,10 @@ function! ale_linters#php#phpstan#FindConfigFile(buffer) abort
|
||||
let l:result = ale#path#FindNearestFile(a:buffer, 'phpstan.neon.dist')
|
||||
endif
|
||||
|
||||
if empty(l:result)
|
||||
let l:result = ale#path#FindNearestFile(a:buffer, 'phpstan.dist.neon')
|
||||
endif
|
||||
|
||||
return l:result
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -19,20 +19,34 @@ function! ale#fixers#rubocop#PostProcess(buffer, output) abort
|
||||
return a:output[l:line :]
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#rubocop#GetCommand(buffer) abort
|
||||
function! ale#fixers#rubocop#GetCommand(buffer, version) abort
|
||||
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
|
||||
let l:options = ale#Var(a:buffer, 'ruby_rubocop_options')
|
||||
let l:auto_correct_all = ale#Var(a:buffer, 'ruby_rubocop_auto_correct_all')
|
||||
let l:editor_mode = ale#semver#GTE(a:version, [1, 61, 0])
|
||||
|
||||
return ale#ruby#EscapeExecutable(l:executable, 'rubocop')
|
||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||
\ . (l:auto_correct_all ? ' --auto-correct-all' : ' --auto-correct')
|
||||
\ . (l:editor_mode ? ' --editor-mode' : '')
|
||||
\ . ' --force-exclusion --stdin %s'
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#rubocop#Fix(buffer) abort
|
||||
function! ale#fixers#rubocop#GetCommandForVersion(buffer, version) abort
|
||||
return {
|
||||
\ 'command': ale#fixers#rubocop#GetCommand(a:buffer),
|
||||
\ 'process_with': 'ale#fixers#rubocop#PostProcess'
|
||||
\ 'command': ale#fixers#rubocop#GetCommand(a:buffer, a:version),
|
||||
\ 'process_with': 'ale#fixers#rubocop#PostProcess'
|
||||
\}
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#rubocop#Fix(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
|
||||
let l:command = l:executable . ale#Pad('--version')
|
||||
|
||||
return ale#semver#RunWithVersionCheck(
|
||||
\ a:buffer,
|
||||
\ l:executable,
|
||||
\ l:command,
|
||||
\ function('ale#fixers#rubocop#GetCommandForVersion'),
|
||||
\)
|
||||
endfunction
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -336,6 +336,7 @@ Notes:
|
||||
* `xo`
|
||||
* Jinja
|
||||
* djlint
|
||||
* j2lint
|
||||
* JSON
|
||||
* `VSCode JSON language server`
|
||||
* `biome`
|
||||
|
||||
@@ -79,11 +79,11 @@ iverilog *ale-verilog-iverilog*
|
||||
===============================================================================
|
||||
slang *ale-verilog-slang*
|
||||
|
||||
*ale-options.verilog_slang_option*
|
||||
*g:ale_verilog_slang_option*
|
||||
*ale-options.verilog_slang_options*
|
||||
*g:ale_verilog_slang_options*
|
||||
*b:ale_verilog_slang_options*
|
||||
verilog_slang_option
|
||||
g:ale_verilog_slang_option
|
||||
verilog_slang_options
|
||||
g:ale_verilog_slang_options
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
|
||||
@@ -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|
|
||||
|
||||
@@ -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/)
|
||||
|
||||
@@ -1,53 +1,47 @@
|
||||
Before:
|
||||
Save g:ale_ruby_rubocop_executable
|
||||
Save g:ale_ruby_rubocop_options
|
||||
|
||||
" Use an invalid global executable, so we don't match it.
|
||||
let g:ale_ruby_rubocop_executable = 'xxxinvalid'
|
||||
let g:ale_ruby_rubocop_options = ''
|
||||
|
||||
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||
call ale#assert#SetUpFixerTest('ruby', 'rubocop')
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
call ale#test#RestoreDirectory()
|
||||
call ale#assert#TearDownFixerTest()
|
||||
|
||||
Execute(The rubocop callback should return the correct default values):
|
||||
call ale#test#SetFilename('../test-files/ruby/dummy.rb')
|
||||
|
||||
AssertEqual
|
||||
GivenCommandOutput ['1.61.0']
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
||||
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
||||
\ . ' --auto-correct --force-exclusion --stdin %s',
|
||||
\ },
|
||||
\ ale#fixers#rubocop#Fix(bufnr(''))
|
||||
\ . ' --auto-correct --editor-mode --force-exclusion --stdin %s',
|
||||
\ }
|
||||
|
||||
Execute(The rubocop callback should include custom rubocop options):
|
||||
let g:ale_ruby_rubocop_options = '--except Lint/Debugger'
|
||||
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')
|
||||
|
||||
AssertEqual
|
||||
GivenCommandOutput ['1.61.0']
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
||||
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
||||
\ . ' --except Lint/Debugger'
|
||||
\ . ' --auto-correct --force-exclusion --stdin %s',
|
||||
\ },
|
||||
\ ale#fixers#rubocop#Fix(bufnr(''))
|
||||
\ . ' --auto-correct --editor-mode --force-exclusion --stdin %s',
|
||||
\ }
|
||||
|
||||
Execute(The rubocop callback should use auto-correct-all option when set):
|
||||
let g:ale_ruby_rubocop_auto_correct_all = 1
|
||||
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')
|
||||
|
||||
AssertEqual
|
||||
GivenCommandOutput ['1.61.0']
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
||||
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
||||
\ . ' --auto-correct-all --force-exclusion --stdin %s'
|
||||
\ },
|
||||
\ ale#fixers#rubocop#Fix(bufnr(''))
|
||||
\ . ' --auto-correct-all --editor-mode --force-exclusion --stdin %s'
|
||||
\ }
|
||||
|
||||
Execute(The rubocop post-processor should remove diagnostics content):
|
||||
AssertEqual
|
||||
@@ -87,3 +81,16 @@ Execute(The rubocop post-processor should remove diagnostics content):
|
||||
\ ' ''forrest'',',
|
||||
\ ' ''run'']',
|
||||
\ ])
|
||||
|
||||
Execute(The rubocop callback should not use editor-mode option with older versions):
|
||||
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')
|
||||
|
||||
GivenCommandOutput ['1.59.0']
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
||||
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
||||
\ . ' --auto-correct --force-exclusion --stdin %s'
|
||||
\ }
|
||||
|
||||
|
||||
44
test/linter/test_j2lint.vader
Normal file
44
test/linter/test_j2lint.vader
Normal file
@@ -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'
|
||||
@@ -59,6 +59,13 @@ Execute(project with level set to 3):
|
||||
AssertLinter 'phpstan',
|
||||
\ ale#Escape('phpstan') . ' analyze --no-progress --errorFormat json -l ' . ale#Escape('3') . ' %s'
|
||||
|
||||
Execute(project with level set to 0):
|
||||
call ale#test#SetFilename('phpstan-test-files/foo/test.php')
|
||||
let g:ale_php_phpstan_level = 0
|
||||
|
||||
AssertLinter 'phpstan',
|
||||
\ ale#Escape('phpstan') . ' analyze --no-progress --errorFormat json -l ' . ale#Escape('0') . ' %s'
|
||||
|
||||
Execute(Custom phpstan configuration file):
|
||||
let g:ale_php_phpstan_configuration = 'phpstan_config'
|
||||
|
||||
@@ -95,6 +102,17 @@ Execute(Configuration dist file exists in current directory):
|
||||
\ ]
|
||||
AssertLinterCwd g:dir
|
||||
|
||||
Execute(Configuration alternative dist file exists in current directory):
|
||||
call writefile(['parameters:', ' level: 7'], './phpstan.dist.neon')
|
||||
let g:ale_php_phpstan_level = ''
|
||||
let g:ale_php_phpstan_configuration = ''
|
||||
|
||||
AssertLinter 'phpstan', [
|
||||
\ ale#Escape('phpstan') . ' --version',
|
||||
\ ale#Escape('phpstan') . ' analyze --no-progress --errorFormat json %s'
|
||||
\ ]
|
||||
AssertLinterCwd g:dir
|
||||
|
||||
Execute(Configuration file exists in current directory, but force phpstan level):
|
||||
call writefile(['parameters:', ' level: 7'], './phpstan.neon')
|
||||
let g:ale_php_phpstan_configuration = ''
|
||||
|
||||
Reference in New Issue
Block a user