mirror of
https://github.com/dense-analysis/ale.git
synced 2026-09-20 10:43:13 +08:00
Compare commits
5
Commits
4217461c48
...
d2f4090c33
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2f4090c33 | ||
|
|
59c6b4f7b0 | ||
|
|
21d5de18b2 | ||
|
|
ed26d1f1d9 | ||
|
|
9811114948 |
@@ -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')
|
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 empty(l:level) && empty(ale_linters#php#phpstan#FindConfigFile(a:buffer))
|
||||||
" if no configuration file is found, then use 4 as a default level
|
" if no configuration file is found, then use 4 as a default level
|
||||||
let l:level = '4'
|
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')
|
let l:result = ale#path#FindNearestFile(a:buffer, 'phpstan.neon.dist')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if empty(l:result)
|
||||||
|
let l:result = ale#path#FindNearestFile(a:buffer, 'phpstan.dist.neon')
|
||||||
|
endif
|
||||||
|
|
||||||
return l:result
|
return l:result
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -19,20 +19,34 @@ function! ale#fixers#rubocop#PostProcess(buffer, output) abort
|
|||||||
return a:output[l:line :]
|
return a:output[l:line :]
|
||||||
endfunction
|
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:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
|
||||||
let l:options = ale#Var(a:buffer, 'ruby_rubocop_options')
|
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: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')
|
return ale#ruby#EscapeExecutable(l:executable, 'rubocop')
|
||||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||||
\ . (l:auto_correct_all ? ' --auto-correct-all' : ' --auto-correct')
|
\ . (l:auto_correct_all ? ' --auto-correct-all' : ' --auto-correct')
|
||||||
|
\ . (l:editor_mode ? ' --editor-mode' : '')
|
||||||
\ . ' --force-exclusion --stdin %s'
|
\ . ' --force-exclusion --stdin %s'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#fixers#rubocop#Fix(buffer) abort
|
function! ale#fixers#rubocop#GetCommandForVersion(buffer, version) abort
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#fixers#rubocop#GetCommand(a:buffer),
|
\ 'command': ale#fixers#rubocop#GetCommand(a:buffer, a:version),
|
||||||
\ 'process_with': 'ale#fixers#rubocop#PostProcess'
|
\ 'process_with': 'ale#fixers#rubocop#PostProcess'
|
||||||
\}
|
\}
|
||||||
endfunction
|
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|
|
See |ale-html-djlint|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
j2lint *ale-jinja-j2lint*
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
|||||||
@@ -336,6 +336,7 @@ Notes:
|
|||||||
* `xo`
|
* `xo`
|
||||||
* Jinja
|
* Jinja
|
||||||
* djlint
|
* djlint
|
||||||
|
* j2lint
|
||||||
* JSON
|
* JSON
|
||||||
* `VSCode JSON language server`
|
* `VSCode JSON language server`
|
||||||
* `biome`
|
* `biome`
|
||||||
|
|||||||
+4
-4
@@ -79,11 +79,11 @@ iverilog *ale-verilog-iverilog*
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
slang *ale-verilog-slang*
|
slang *ale-verilog-slang*
|
||||||
|
|
||||||
*ale-options.verilog_slang_option*
|
*ale-options.verilog_slang_options*
|
||||||
*g:ale_verilog_slang_option*
|
*g:ale_verilog_slang_options*
|
||||||
*b:ale_verilog_slang_options*
|
*b:ale_verilog_slang_options*
|
||||||
verilog_slang_option
|
verilog_slang_options
|
||||||
g:ale_verilog_slang_option
|
g:ale_verilog_slang_options
|
||||||
Type: |String|
|
Type: |String|
|
||||||
Default: `''`
|
Default: `''`
|
||||||
|
|
||||||
|
|||||||
@@ -3634,6 +3634,7 @@ documented in additional help files.
|
|||||||
xo....................................|ale-javascript-xo|
|
xo....................................|ale-javascript-xo|
|
||||||
jinja...................................|ale-jinja-options|
|
jinja...................................|ale-jinja-options|
|
||||||
djlint................................|ale-jinja-djlint|
|
djlint................................|ale-jinja-djlint|
|
||||||
|
j2lint................................|ale-jinja-j2lint|
|
||||||
json....................................|ale-json-options|
|
json....................................|ale-json-options|
|
||||||
biome.................................|ale-json-biome|
|
biome.................................|ale-json-biome|
|
||||||
clang-format..........................|ale-json-clangformat|
|
clang-format..........................|ale-json-clangformat|
|
||||||
|
|||||||
@@ -346,6 +346,7 @@ formatting.
|
|||||||
* [xo](https://github.com/sindresorhus/xo)
|
* [xo](https://github.com/sindresorhus/xo)
|
||||||
* Jinja
|
* Jinja
|
||||||
* [djlint](https://djlint.com/)
|
* [djlint](https://djlint.com/)
|
||||||
|
* [j2lint](https://github.com/aristanetworks/j2lint/)
|
||||||
* JSON
|
* JSON
|
||||||
* [VSCode JSON language server](https://github.com/hrsh7th/vscode-langservers-extracted)
|
* [VSCode JSON language server](https://github.com/hrsh7th/vscode-langservers-extracted)
|
||||||
* [biome](https://biomejs.dev/)
|
* [biome](https://biomejs.dev/)
|
||||||
|
|||||||
@@ -1,53 +1,47 @@
|
|||||||
Before:
|
Before:
|
||||||
Save g:ale_ruby_rubocop_executable
|
call ale#assert#SetUpFixerTest('ruby', 'rubocop')
|
||||||
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')
|
|
||||||
|
|
||||||
After:
|
After:
|
||||||
Restore
|
call ale#assert#TearDownFixerTest()
|
||||||
|
|
||||||
call ale#test#RestoreDirectory()
|
|
||||||
|
|
||||||
Execute(The rubocop callback should return the correct default values):
|
Execute(The rubocop callback should return the correct default values):
|
||||||
call ale#test#SetFilename('../test-files/ruby/dummy.rb')
|
call ale#test#SetFilename('../test-files/ruby/dummy.rb')
|
||||||
|
|
||||||
AssertEqual
|
GivenCommandOutput ['1.61.0']
|
||||||
|
|
||||||
|
AssertFixer
|
||||||
\ {
|
\ {
|
||||||
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
||||||
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
||||||
\ . ' --auto-correct --force-exclusion --stdin %s',
|
\ . ' --auto-correct --editor-mode --force-exclusion --stdin %s',
|
||||||
\ },
|
\ }
|
||||||
\ ale#fixers#rubocop#Fix(bufnr(''))
|
|
||||||
|
|
||||||
Execute(The rubocop callback should include custom rubocop options):
|
Execute(The rubocop callback should include custom rubocop options):
|
||||||
let g:ale_ruby_rubocop_options = '--except Lint/Debugger'
|
let g:ale_ruby_rubocop_options = '--except Lint/Debugger'
|
||||||
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')
|
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')
|
||||||
|
|
||||||
AssertEqual
|
GivenCommandOutput ['1.61.0']
|
||||||
|
|
||||||
|
AssertFixer
|
||||||
\ {
|
\ {
|
||||||
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
||||||
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
||||||
\ . ' --except Lint/Debugger'
|
\ . ' --except Lint/Debugger'
|
||||||
\ . ' --auto-correct --force-exclusion --stdin %s',
|
\ . ' --auto-correct --editor-mode --force-exclusion --stdin %s',
|
||||||
\ },
|
\ }
|
||||||
\ ale#fixers#rubocop#Fix(bufnr(''))
|
|
||||||
|
|
||||||
Execute(The rubocop callback should use auto-correct-all option when set):
|
Execute(The rubocop callback should use auto-correct-all option when set):
|
||||||
let g:ale_ruby_rubocop_auto_correct_all = 1
|
let g:ale_ruby_rubocop_auto_correct_all = 1
|
||||||
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')
|
call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')
|
||||||
|
|
||||||
AssertEqual
|
GivenCommandOutput ['1.61.0']
|
||||||
|
|
||||||
|
AssertFixer
|
||||||
\ {
|
\ {
|
||||||
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
|
||||||
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
|
||||||
\ . ' --auto-correct-all --force-exclusion --stdin %s'
|
\ . ' --auto-correct-all --editor-mode --force-exclusion --stdin %s'
|
||||||
\ },
|
\ }
|
||||||
\ ale#fixers#rubocop#Fix(bufnr(''))
|
|
||||||
|
|
||||||
Execute(The rubocop post-processor should remove diagnostics content):
|
Execute(The rubocop post-processor should remove diagnostics content):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
@@ -87,3 +81,16 @@ Execute(The rubocop post-processor should remove diagnostics content):
|
|||||||
\ ' ''forrest'',',
|
\ ' ''forrest'',',
|
||||||
\ ' ''run'']',
|
\ ' ''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'
|
||||||
|
\ }
|
||||||
|
|
||||||
|
|||||||
@@ -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',
|
AssertLinter 'phpstan',
|
||||||
\ ale#Escape('phpstan') . ' analyze --no-progress --errorFormat json -l ' . ale#Escape('3') . ' %s'
|
\ 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):
|
Execute(Custom phpstan configuration file):
|
||||||
let g:ale_php_phpstan_configuration = 'phpstan_config'
|
let g:ale_php_phpstan_configuration = 'phpstan_config'
|
||||||
|
|
||||||
@@ -95,6 +102,17 @@ Execute(Configuration dist file exists in current directory):
|
|||||||
\ ]
|
\ ]
|
||||||
AssertLinterCwd g:dir
|
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):
|
Execute(Configuration file exists in current directory, but force phpstan level):
|
||||||
call writefile(['parameters:', ' level: 7'], './phpstan.neon')
|
call writefile(['parameters:', ' level: 7'], './phpstan.neon')
|
||||||
let g:ale_php_phpstan_configuration = ''
|
let g:ale_php_phpstan_configuration = ''
|
||||||
|
|||||||
Reference in New Issue
Block a user