mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 12:44:23 +08:00
Reduce lines of code for tombi
This commit is contained in:
@@ -4,13 +4,6 @@
|
||||
call ale#Set('toml_tombi_executable', 'tombi')
|
||||
call ale#Set('toml_tombi_lsp_options', '')
|
||||
|
||||
function! ale_linters#toml#tombi#GetCommand(buffer) abort
|
||||
let l:options = ale#Var(a:buffer, 'toml_tombi_lsp_options')
|
||||
|
||||
return '%e lsp'
|
||||
\ . (empty(l:options) ? '' : ' ' . l:options)
|
||||
endfunction
|
||||
|
||||
function! ale_linters#toml#tombi#GetProjectRoot(buffer) abort
|
||||
" Try to find nearest tombi.toml
|
||||
let l:tombiconfig_file = ale#path#FindNearestFile(a:buffer, 'tombi.toml')
|
||||
@@ -40,6 +33,6 @@ call ale#linter#Define('toml', {
|
||||
\ 'name': 'tombi',
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'executable': {b -> ale#Var(b, 'toml_tombi_executable')},
|
||||
\ 'command': function('ale_linters#toml#tombi#GetCommand'),
|
||||
\ 'command': {b -> '%e lsp' . ale#Pad(ale#Var(b, 'toml_tombi_lsp_options'))},
|
||||
\ 'project_root': function('ale_linters#toml#tombi#GetProjectRoot'),
|
||||
\})
|
||||
|
||||
@@ -6,11 +6,10 @@ call ale#Set('toml_tombi_format_options', '')
|
||||
|
||||
function! ale#fixers#tombi_format#Fix(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
||||
let l:options = ale#Var(a:buffer, 'toml_tombi_format_options')
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(l:executable)
|
||||
\ . ' format'
|
||||
\ . (empty(l:options) ? '' : ' ' . l:options),
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'toml_tombi_format_options')),
|
||||
\}
|
||||
endfunction
|
||||
|
||||
@@ -6,11 +6,10 @@ call ale#Set('toml_tombi_lint_options', '')
|
||||
|
||||
function! ale#fixers#tombi_lint#Fix(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
||||
let l:options = ale#Var(a:buffer, 'toml_tombi_lint_options')
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(l:executable)
|
||||
\ . ' lint'
|
||||
\ . (empty(l:options) ? '' : ' ' . l:options),
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'toml_tombi_lint_options')),
|
||||
\}
|
||||
endfunction
|
||||
|
||||
@@ -14,20 +14,13 @@ After:
|
||||
call ale#test#RestoreDirectory()
|
||||
|
||||
Execute(The tombi format callback should return the correct default values):
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': ale#Escape('xxxinvalid') . ' format',
|
||||
\ },
|
||||
\ {'command': ale#Escape('xxxinvalid') . ' format'},
|
||||
\ ale#fixers#tombi_format#Fix(bufnr(''))
|
||||
|
||||
Execute(The tombi format callback should include custom options):
|
||||
let g:ale_toml_tombi_format_options = "--offline"
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': ale#Escape('xxxinvalid')
|
||||
\ . ' format'
|
||||
\ . ' ' . g:ale_toml_tombi_format_options
|
||||
\ },
|
||||
\ {'command': ale#Escape('xxxinvalid') . ' format --offline'},
|
||||
\ ale#fixers#tombi_format#Fix(bufnr(''))
|
||||
|
||||
@@ -14,20 +14,13 @@ After:
|
||||
call ale#test#RestoreDirectory()
|
||||
|
||||
Execute(The tombi lint callback should return the correct default values):
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': ale#Escape('xxxinvalid') . ' lint',
|
||||
\ },
|
||||
\ {'command': ale#Escape('xxxinvalid') . ' lint'},
|
||||
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
||||
|
||||
Execute(The tombi lint callback should include custom options):
|
||||
let g:ale_toml_tombi_lint_options = "--offline"
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': ale#Escape('xxxinvalid')
|
||||
\ . ' lint'
|
||||
\ . ' ' . g:ale_toml_tombi_lint_options
|
||||
\ },
|
||||
\ {'command': ale#Escape('xxxinvalid') . ' lint --offline'},
|
||||
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
||||
|
||||
@@ -16,8 +16,3 @@ Execute(The project root should be detected correctly in Python projects):
|
||||
call ale#test#SetFilename('../test-files/toml/tombi/pyprojecttoml/subdir/file.ext')
|
||||
|
||||
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/toml/tombi/pyprojecttoml')
|
||||
|
||||
Execute(The project root should be empty when no project files can be detected):
|
||||
call ale#test#SetFilename('../test-files/dummy')
|
||||
|
||||
AssertLSPProject ''
|
||||
|
||||
Reference in New Issue
Block a user