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_executable', 'tombi')
|
||||||
call ale#Set('toml_tombi_lsp_options', '')
|
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
|
function! ale_linters#toml#tombi#GetProjectRoot(buffer) abort
|
||||||
" Try to find nearest tombi.toml
|
" Try to find nearest tombi.toml
|
||||||
let l:tombiconfig_file = ale#path#FindNearestFile(a:buffer, 'tombi.toml')
|
let l:tombiconfig_file = ale#path#FindNearestFile(a:buffer, 'tombi.toml')
|
||||||
@@ -40,6 +33,6 @@ call ale#linter#Define('toml', {
|
|||||||
\ 'name': 'tombi',
|
\ 'name': 'tombi',
|
||||||
\ 'lsp': 'stdio',
|
\ 'lsp': 'stdio',
|
||||||
\ 'executable': {b -> ale#Var(b, 'toml_tombi_executable')},
|
\ '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'),
|
\ '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
|
function! ale#fixers#tombi_format#Fix(buffer) abort
|
||||||
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
||||||
let l:options = ale#Var(a:buffer, 'toml_tombi_format_options')
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#Escape(l:executable)
|
\ 'command': ale#Escape(l:executable)
|
||||||
\ . ' format'
|
\ . ' format'
|
||||||
\ . (empty(l:options) ? '' : ' ' . l:options),
|
\ . ale#Pad(ale#Var(a:buffer, 'toml_tombi_format_options')),
|
||||||
\}
|
\}
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ call ale#Set('toml_tombi_lint_options', '')
|
|||||||
|
|
||||||
function! ale#fixers#tombi_lint#Fix(buffer) abort
|
function! ale#fixers#tombi_lint#Fix(buffer) abort
|
||||||
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
||||||
let l:options = ale#Var(a:buffer, 'toml_tombi_lint_options')
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#Escape(l:executable)
|
\ 'command': ale#Escape(l:executable)
|
||||||
\ . ' lint'
|
\ . ' lint'
|
||||||
\ . (empty(l:options) ? '' : ' ' . l:options),
|
\ . ale#Pad(ale#Var(a:buffer, 'toml_tombi_lint_options')),
|
||||||
\}
|
\}
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -14,20 +14,13 @@ After:
|
|||||||
call ale#test#RestoreDirectory()
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
Execute(The tombi format callback should return the correct default values):
|
Execute(The tombi format callback should return the correct default values):
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {'command': ale#Escape('xxxinvalid') . ' format'},
|
||||||
\ 'command': ale#Escape('xxxinvalid') . ' format',
|
|
||||||
\ },
|
|
||||||
\ ale#fixers#tombi_format#Fix(bufnr(''))
|
\ ale#fixers#tombi_format#Fix(bufnr(''))
|
||||||
|
|
||||||
Execute(The tombi format callback should include custom options):
|
Execute(The tombi format callback should include custom options):
|
||||||
let g:ale_toml_tombi_format_options = "--offline"
|
let g:ale_toml_tombi_format_options = "--offline"
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {'command': ale#Escape('xxxinvalid') . ' format --offline'},
|
||||||
\ 'command': ale#Escape('xxxinvalid')
|
|
||||||
\ . ' format'
|
|
||||||
\ . ' ' . g:ale_toml_tombi_format_options
|
|
||||||
\ },
|
|
||||||
\ ale#fixers#tombi_format#Fix(bufnr(''))
|
\ ale#fixers#tombi_format#Fix(bufnr(''))
|
||||||
|
|||||||
@@ -14,20 +14,13 @@ After:
|
|||||||
call ale#test#RestoreDirectory()
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
Execute(The tombi lint callback should return the correct default values):
|
Execute(The tombi lint callback should return the correct default values):
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {'command': ale#Escape('xxxinvalid') . ' lint'},
|
||||||
\ 'command': ale#Escape('xxxinvalid') . ' lint',
|
|
||||||
\ },
|
|
||||||
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
||||||
|
|
||||||
Execute(The tombi lint callback should include custom options):
|
Execute(The tombi lint callback should include custom options):
|
||||||
let g:ale_toml_tombi_lint_options = "--offline"
|
let g:ale_toml_tombi_lint_options = "--offline"
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {'command': ale#Escape('xxxinvalid') . ' lint --offline'},
|
||||||
\ 'command': ale#Escape('xxxinvalid')
|
|
||||||
\ . ' lint'
|
|
||||||
\ . ' ' . g:ale_toml_tombi_lint_options
|
|
||||||
\ },
|
|
||||||
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
\ 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')
|
call ale#test#SetFilename('../test-files/toml/tombi/pyprojecttoml/subdir/file.ext')
|
||||||
|
|
||||||
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/toml/tombi/pyprojecttoml')
|
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