summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--ale_linters/ada/gcc.vim2
-rw-r--r--ale_linters/cs/mcsc.vim2
-rw-r--r--ale_linters/cuda/nvcc.vim2
-rw-r--r--ale_linters/elixir/mix.vim2
-rw-r--r--ale_linters/erlang/erlc.vim2
-rw-r--r--ale_linters/java/javac.vim2
-rw-r--r--ale_linters/python/bandit.vim58
-rw-r--r--ale_linters/thrift/thrift.vim2
-rw-r--r--ale_linters/verilog/verilator.vim2
-rw-r--r--ale_linters/vim/ale_custom_linting_rules.vim2
-rw-r--r--autoload/ale/assert.vim13
-rw-r--r--autoload/ale/command.vim135
-rw-r--r--autoload/ale/debugging.vim1
-rw-r--r--autoload/ale/engine.vim94
-rw-r--r--autoload/ale/fix.vim70
-rw-r--r--autoload/ale/lsp_linter.vim37
-rw-r--r--doc/ale-python.txt39
-rw-r--r--doc/ale.txt73
-rw-r--r--plugin/ale.vim3
-rw-r--r--test/command_callback/test_bandit_command_callback.vader49
-rw-r--r--test/handler/test_bandit_handler.vader42
-rw-r--r--test/lsp/test_lsp_command_formatting.vader1
-rw-r--r--test/lsp/test_lsp_root_detection.vader63
-rw-r--r--test/test_ale_info.vader1
-rw-r--r--test/test_format_command.vader42
-rw-r--r--test/test_sandbox_execution.vader2
-rw-r--r--test/test_temporary_file_management.vader44
28 files changed, 572 insertions, 217 deletions
diff --git a/README.md b/README.md
index 9eebf5d1..b408af03 100644
--- a/README.md
+++ b/README.md
@@ -144,7 +144,7 @@ formatting.
| Idris | [idris](http://www.idris-lang.org/) |
| ISPC | [ispc](https://ispc.github.io/) !! |
| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format), [PMD](https://pmd.github.io/), [javalsp](https://github.com/georgewfraser/vscode-javac), [uncrustify](https://github.com/uncrustify/uncrustify) |
-| JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), [prettier-eslint](https://github.com/prettier/prettier-eslint-cli), [prettier-standard](https://github.com/sheerun/prettier-standard), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo)
+| JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), [prettier-eslint](https://github.com/prettier/prettier-eslint-cli), [prettier-standard](https://github.com/sheerun/prettier-standard), [standard](http://standardjs.com/), [tsserver](https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29), [xo](https://github.com/sindresorhus/xo)
| JSON | [fixjson](https://github.com/rhysd/fixjson), [jsonlint](http://zaa.ch/jsonlint/), [jq](https://stedolan.github.io/jq/), [prettier](https://github.com/prettier/prettier) |
| Julia | [languageserver](https://github.com/JuliaEditorSupport/LanguageServer.jl) |
| Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !!, [languageserver](https://github.com/fwcd/KotlinLanguageServer) see `:help ale-integration-kotlin` for configuration instructions |
@@ -175,7 +175,7 @@ formatting.
| proto | [protoc-gen-lint](https://github.com/ckaznocha/protoc-gen-lint) |
| Pug | [pug-lint](https://github.com/pugjs/pug-lint) |
| Puppet | [languageserver](https://github.com/lingua-pupuli/puppet-editor-services), [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) |
-| Python | [autopep8](https://github.com/hhatto/autopep8), [black](https://github.com/ambv/black), [flake8](http://flake8.pycqa.org/en/latest/), [isort](https://github.com/timothycrosley/isort), [mypy](http://mypy-lang.org/), [prospector](https://github.com/PyCQA/prospector), [pycodestyle](https://github.com/PyCQA/pycodestyle), [pydocstyle](https://www.pydocstyle.org/), [pyls](https://github.com/palantir/python-language-server), [pyre](https://github.com/facebook/pyre-check), [pylint](https://www.pylint.org/) !!, [vulture](https://github.com/jendrikseipp/vulture) !!, [yapf](https://github.com/google/yapf) |
+| Python | [autopep8](https://github.com/hhatto/autopep8), [bandit](https://github.com/PyCQA/bandit), [black](https://github.com/ambv/black), [flake8](http://flake8.pycqa.org/en/latest/), [isort](https://github.com/timothycrosley/isort), [mypy](http://mypy-lang.org/), [prospector](https://github.com/PyCQA/prospector), [pycodestyle](https://github.com/PyCQA/pycodestyle), [pydocstyle](https://www.pydocstyle.org/), [pyls](https://github.com/palantir/python-language-server), [pyre](https://github.com/facebook/pyre-check), [pylint](https://www.pylint.org/) !!, [vulture](https://github.com/jendrikseipp/vulture) !!, [yapf](https://github.com/google/yapf) |
| QML | [qmlfmt](https://github.com/jesperhh/qmlfmt), [qmllint](https://github.com/qt/qtdeclarative/tree/5.11/tools/qmllint) |
| R | [lintr](https://github.com/jimhester/lintr) |
| Racket | [raco](https://docs.racket-lang.org/raco/) |
diff --git a/ale_linters/ada/gcc.vim b/ale_linters/ada/gcc.vim
index d6f973ae..7b0c4809 100644
--- a/ale_linters/ada/gcc.vim
+++ b/ale_linters/ada/gcc.vim
@@ -12,7 +12,7 @@ function! ale_linters#ada#gcc#GetCommand(buffer) abort
" the .ali file may be created even if no code generation is attempted.
" The output file name must match the source file name (except for the
" extension), so here we cannot use the null file as output.
- let l:tmp_dir = fnamemodify(ale#engine#CreateDirectory(a:buffer), ':p')
+ let l:tmp_dir = fnamemodify(ale#command#CreateDirectory(a:buffer), ':p')
let l:out_file = l:tmp_dir . fnamemodify(bufname(a:buffer), ':t:r') . '.o'
" -gnatc: Check syntax and semantics only (no code generation attempted)
diff --git a/ale_linters/cs/mcsc.vim b/ale_linters/cs/mcsc.vim
index 1561661e..a169297c 100644
--- a/ale_linters/cs/mcsc.vim
+++ b/ale_linters/cs/mcsc.vim
@@ -30,7 +30,7 @@ function! ale_linters#cs#mcsc#GetCommand(buffer) abort
" register temporary module target file with ale
" register temporary module target file with ALE.
- let l:out = ale#engine#CreateFile(a:buffer)
+ let l:out = ale#command#CreateFile(a:buffer)
" The code is compiled as a module and the output is redirected to a
" temporary file.
diff --git a/ale_linters/cuda/nvcc.vim b/ale_linters/cuda/nvcc.vim
index f4442cb8..db789ff1 100644
--- a/ale_linters/cuda/nvcc.vim
+++ b/ale_linters/cuda/nvcc.vim
@@ -7,7 +7,7 @@ call ale#Set('cuda_nvcc_options', '-std=c++11')
function! ale_linters#cuda#nvcc#GetCommand(buffer) abort
" Unused: use ale#util#nul_file
" let l:output_file = ale#util#Tempname() . '.ii'
- " call ale#engine#ManageFile(a:buffer, l:output_file)
+ " call ale#command#ManageFile(a:buffer, l:output_file)
return '%e -cuda'
\ . ale#Pad(ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)))
\ . ale#Pad(ale#Var(a:buffer, 'cuda_nvcc_options'))
diff --git a/ale_linters/elixir/mix.vim b/ale_linters/elixir/mix.vim
index dc3c1818..59cfe505 100644
--- a/ale_linters/elixir/mix.vim
+++ b/ale_linters/elixir/mix.vim
@@ -32,7 +32,7 @@ endfunction
function! ale_linters#elixir#mix#GetCommand(buffer) abort
let l:project_root = ale#handlers#elixir#FindMixProjectRoot(a:buffer)
- let l:temp_dir = ale#engine#CreateDirectory(a:buffer)
+ let l:temp_dir = ale#command#CreateDirectory(a:buffer)
let l:mix_build_path = has('win32')
\ ? 'set MIX_BUILD_PATH=' . ale#Escape(l:temp_dir) . ' &&'
diff --git a/ale_linters/erlang/erlc.vim b/ale_linters/erlang/erlc.vim
index 0bdb4dea..81ba128b 100644
--- a/ale_linters/erlang/erlc.vim
+++ b/ale_linters/erlang/erlc.vim
@@ -4,7 +4,7 @@ let g:ale_erlang_erlc_options = get(g:, 'ale_erlang_erlc_options', '')
function! ale_linters#erlang#erlc#GetCommand(buffer) abort
let l:output_file = ale#util#Tempname()
- call ale#engine#ManageFile(a:buffer, l:output_file)
+ call ale#command#ManageFile(a:buffer, l:output_file)
return 'erlc -o ' . ale#Escape(l:output_file)
\ . ' ' . ale#Var(a:buffer, 'erlang_erlc_options')
diff --git a/ale_linters/java/javac.vim b/ale_linters/java/javac.vim
index 63dcdd94..2aa01b4f 100644
--- a/ale_linters/java/javac.vim
+++ b/ale_linters/java/javac.vim
@@ -73,7 +73,7 @@ function! ale_linters#java#javac#GetCommand(buffer, import_paths) abort
endif
" Create .class files in a temporary directory, which we will delete later.
- let l:class_file_directory = ale#engine#CreateDirectory(a:buffer)
+ let l:class_file_directory = ale#command#CreateDirectory(a:buffer)
" Always run javac from the directory the file is in, so we can resolve
" relative paths correctly.
diff --git a/ale_linters/python/bandit.vim b/ale_linters/python/bandit.vim
new file mode 100644
index 00000000..1b5a84a4
--- /dev/null
+++ b/ale_linters/python/bandit.vim
@@ -0,0 +1,58 @@
+" Author: Martino Pilia <martino.pilia@gmail.com>
+" Description: bandit linting for python files
+
+call ale#Set('python_bandit_executable', 'bandit')
+call ale#Set('python_bandit_options', '')
+call ale#Set('python_bandit_use_global', get(g:, 'ale_use_global_executables', 0))
+call ale#Set('python_bandit_auto_pipenv', 0)
+
+function! ale_linters#python#bandit#GetExecutable(buffer) abort
+ if (ale#Var(a:buffer, 'python_auto_pipenv') ||
+ \ ale#Var(a:buffer, 'python_bandit_auto_pipenv'))
+ \ && ale#python#PipenvPresent(a:buffer)
+ return 'pipenv'
+ endif
+
+ return ale#python#FindExecutable(a:buffer, 'python_bandit', ['bandit'])
+endfunction
+
+function! ale_linters#python#bandit#GetCommand(buffer) abort
+ let l:executable = ale_linters#python#bandit#GetExecutable(a:buffer)
+ let l:flags = ' --format custom'
+ \ . ' --msg-template "{line}:{test_id}:{severity}:{msg}" '
+
+ let l:exec_args = l:executable =~? 'pipenv$'
+ \ ? ' run bandit'
+ \ : ''
+
+ return ale#Escape(l:executable) . l:exec_args
+ \ . l:flags
+ \ . ale#Pad(ale#Var(a:buffer, 'python_bandit_options'))
+ \ . ' -'
+endfunction
+
+function! ale_linters#python#bandit#Handle(buffer, lines) abort
+ " Custom format defined in GetCommand via --msg-template
+ let l:pattern = '\v^([0-9]+):(B[0-9]+):([A-Z]+):(.*)$'
+ let l:severity = {'LOW': 'I', 'MEDIUM': 'W', 'HIGH': 'E'}
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': str2nr(l:match[1]),
+ \ 'code': l:match[2],
+ \ 'type': l:severity[l:match[3]],
+ \ 'text': l:match[4],
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('python', {
+\ 'name': 'bandit',
+\ 'executable_callback': 'ale_linters#python#bandit#GetExecutable',
+\ 'command_callback': 'ale_linters#python#bandit#GetCommand',
+\ 'callback': 'ale_linters#python#bandit#Handle',
+\})
diff --git a/ale_linters/thrift/thrift.vim b/ale_linters/thrift/thrift.vim
index 36a8656e..2f2086c9 100644
--- a/ale_linters/thrift/thrift.vim
+++ b/ale_linters/thrift/thrift.vim
@@ -16,7 +16,7 @@ function! ale_linters#thrift#thrift#GetCommand(buffer) abort
let l:generators = ['cpp']
endif
- let l:output_dir = ale#engine#CreateDirectory(a:buffer)
+ let l:output_dir = ale#command#CreateDirectory(a:buffer)
return '%e'
\ . ale#Pad(join(map(copy(l:generators), "'--gen ' . v:val")))
diff --git a/ale_linters/verilog/verilator.vim b/ale_linters/verilog/verilator.vim
index 83d5f59d..18d99043 100644
--- a/ale_linters/verilog/verilator.vim
+++ b/ale_linters/verilog/verilator.vim
@@ -10,7 +10,7 @@ function! ale_linters#verilog#verilator#GetCommand(buffer) abort
let l:filename = ale#util#Tempname() . '_verilator_linted.v'
" Create a special filename, so we can detect it in the handler.
- call ale#engine#ManageFile(a:buffer, l:filename)
+ call ale#command#ManageFile(a:buffer, l:filename)
let l:lines = getbufline(a:buffer, 1, '$')
call ale#util#Writefile(a:buffer, l:lines, l:filename)
diff --git a/ale_linters/vim/ale_custom_linting_rules.vim b/ale_linters/vim/ale_custom_linting_rules.vim
index 3da44206..3abe5d4b 100644
--- a/ale_linters/vim/ale_custom_linting_rules.vim
+++ b/ale_linters/vim/ale_custom_linting_rules.vim
@@ -25,7 +25,7 @@ endfunction
function! ale_linters#vim#ale_custom_linting_rules#GetCommand(buffer) abort
let l:dir = s:GetALEProjectDir(a:buffer)
- let l:temp_dir = ale#engine#CreateDirectory(a:buffer)
+ let l:temp_dir = ale#command#CreateDirectory(a:buffer)
let l:temp_file = l:temp_dir . '/example.vim'
let l:lines = getbufline(a:buffer, 1, '$')
diff --git a/autoload/ale/assert.vim b/autoload/ale/assert.vim
index ed08ed09..7139f05c 100644
--- a/autoload/ale/assert.vim
+++ b/autoload/ale/assert.vim
@@ -109,6 +109,14 @@ function! ale#assert#LSPProject(expected_root) abort
AssertEqual a:expected_root, l:root
endfunction
+function! ale#assert#LSPProjectFull(expected_root) abort
+ let l:buffer = bufnr('')
+ let l:linter = s:GetLinter()
+ let l:root = ale#lsp_linter#FindProjectRoot(l:buffer, l:linter)
+
+ AssertEqual a:expected_root, l:root
+endfunction
+
function! ale#assert#LSPAddress(expected_address) abort
let l:buffer = bufnr('')
let l:linter = s:GetLinter()
@@ -158,6 +166,7 @@ function! ale#assert#SetUpLinterTest(filetype, name) abort
command! -nargs=+ AssertLSPConfig :call ale#assert#LSPConfig(<args>)
command! -nargs=+ AssertLSPLanguage :call ale#assert#LSPLanguage(<args>)
command! -nargs=+ AssertLSPProject :call ale#assert#LSPProject(<args>)
+ command! -nargs=+ AssertLSPProjectFull :call ale#assert#LSPProjectFull(<args>)
command! -nargs=+ AssertLSPAddress :call ale#assert#LSPAddress(<args>)
endfunction
@@ -193,6 +202,10 @@ function! ale#assert#TearDownLinterTest() abort
delcommand AssertLSPProject
endif
+ if exists(':AssertLSPProjectFull')
+ delcommand AssertLSPProjectFull
+ endif
+
if exists(':AssertLSPAddress')
delcommand AssertLSPAddress
endif
diff --git a/autoload/ale/command.vim b/autoload/ale/command.vim
index 6c56d518..6944f170 100644
--- a/autoload/ale/command.vim
+++ b/autoload/ale/command.vim
@@ -1,6 +1,121 @@
" Author: w0rp <devw0rp@gmail.com>
-" Description: Special command formatting for creating temporary files and
-" passing buffer filenames easily.
+" Description: Functions for formatting command strings, running commands, and
+" managing files during linting and fixing cycles.
+
+" This dictionary holds lists of files and directories to remove later.
+if !exists('s:managed_data')
+ let s:managed_data = {}
+endif
+
+" Used to get the data in tests.
+function! ale#command#GetData() abort
+ return deepcopy(s:managed_data)
+endfunction
+
+function! ale#command#ClearData() abort
+ let s:managed_data = {}
+endfunction
+
+function! ale#command#ManageFile(buffer, file) abort
+ if !has_key(s:managed_data, a:buffer)
+ let s:managed_data[a:buffer] = {'file_list': [], 'directory_list': []}
+ endif
+
+ call add(s:managed_data[a:buffer].file_list, a:file)
+endfunction
+
+function! ale#command#ManageDirectory(buffer, directory) abort
+ if !has_key(s:managed_data, a:buffer)
+ let s:managed_data[a:buffer] = {'file_list': [], 'directory_list': []}
+ endif
+
+ call add(s:managed_data[a:buffer].directory_list, a:directory)
+endfunction
+
+function! ale#command#CreateFile(buffer) abort
+ " This variable can be set to 1 in tests to stub this out.
+ if get(g:, 'ale_create_dummy_temporary_file')
+ return 'TEMP'
+ endif
+
+ let l:temporary_file = ale#util#Tempname()
+ call ale#command#ManageFile(a:buffer, l:temporary_file)
+
+ return l:temporary_file
+endfunction
+
+" Create a new temporary directory and manage it in one go.
+function! ale#command#CreateDirectory(buffer) abort
+ " This variable can be set to 1 in tests to stub this out.
+ if get(g:, 'ale_create_dummy_temporary_file')
+ return 'TEMP_DIR'
+ endif
+
+ let l:temporary_directory = ale#util#Tempname()
+ " Create the temporary directory for the file, unreadable by 'other'
+ " users.
+ call mkdir(l:temporary_directory, '', 0750)
+ call ale#command#ManageDirectory(a:buffer, l:temporary_directory)
+
+ return l:temporary_directory
+endfunction
+
+function! ale#command#RemoveManagedFiles(buffer) abort
+ let l:info = get(s:managed_data, a:buffer, {})
+
+ if !empty(l:info)
+ \&& (
+ \ !exists('*ale#engine#IsCheckingBuffer')
+ \ || !ale#engine#IsCheckingBuffer(a:buffer)
+ \)
+ \&& (
+ \ !has_key(g:ale_fix_buffer_data, a:buffer)
+ \ || g:ale_fix_buffer_data[a:buffer].done
+ \)
+ " We can't delete anything in a sandbox, so wait until we escape from
+ " it to delete temporary files and directories.
+ if ale#util#InSandbox()
+ return
+ endif
+
+ " Delete files with a call akin to a plan `rm` command.
+ for l:filename in l:info.file_list
+ call delete(l:filename)
+ endfor
+
+ " Delete directories like `rm -rf`.
+ " Directories are handled differently from files, so paths that are
+ " intended to be single files can be set up for automatic deletion
+ " without accidentally deleting entire directories.
+ for l:directory in l:info.directory_list
+ call delete(l:directory, 'rf')
+ endfor
+
+ call remove(s:managed_data, a:buffer)
+ endif
+endfunction
+
+function! ale#command#CreateTempFile(buffer, temporary_file, input) abort
+ if empty(a:temporary_file)
+ " There is no file, so we didn't create anything.
+ return 0
+ endif
+
+ " Use an existing list of lines of input if we have it, or get the lines
+ " from the file.
+ let l:lines = a:input isnot v:null ? a:input : getbufline(a:buffer, 1, '$')
+
+ let l:temporary_directory = fnamemodify(a:temporary_file, ':h')
+ " Create the temporary directory for the file, unreadable by 'other'
+ " users.
+ call mkdir(l:temporary_directory, '', 0750)
+ " Automatically delete the directory later.
+ call ale#command#ManageDirectory(a:buffer, l:temporary_directory)
+ " Write the buffer out to a file.
+ call ale#util#Writefile(a:buffer, l:lines, a:temporary_file)
+
+ return 1
+endfunction
function! s:TemporaryFilename(buffer) abort
let l:filename = fnamemodify(bufname(a:buffer), ':t')
@@ -16,11 +131,17 @@ function! s:TemporaryFilename(buffer) abort
return ale#util#Tempname() . (has('win32') ? '\' : '/') . l:filename
endfunction
+" Given part of a command, replace any % with %%, so that no characters in
+" the string will be replaced with filenames, etc.
+function! ale#command#EscapeCommandPart(command_part) abort
+ return substitute(a:command_part, '%', '%%', 'g')
+endfunction
+
" Given a command string, replace every...
" %s -> with the current filename
" %t -> with the name of an unused file in a temporary directory
" %% -> with a literal %
-function! ale#command#FormatCommand(buffer, executable, command, pipe_file_if_needed, CreateTemporaryFileForJob) abort
+function! ale#command#FormatCommand(buffer, executable, command, pipe_file_if_needed, input) abort
let l:temporary_file = ''
let l:command = a:command
@@ -40,7 +161,7 @@ function! ale#command#FormatCommand(buffer, executable, command, pipe_file_if_ne
let l:command = substitute(l:command, '%s', '\=ale#Escape(l:filename)', 'g')
endif
- if l:command =~# '%t'
+ if a:input isnot v:false && l:command =~# '%t'
" Create a temporary filename, <temp_dir>/<original_basename>
" The file itself will not be created by this function.
let l:temporary_file = s:TemporaryFilename(a:buffer)
@@ -58,7 +179,11 @@ function! ale#command#FormatCommand(buffer, executable, command, pipe_file_if_ne
let l:command = l:command . ' < ' . ale#Escape(l:temporary_file)
endif
- let l:file_created = a:CreateTemporaryFileForJob(a:buffer, l:temporary_file)
+ let l:file_created = ale#command#CreateTempFile(
+ \ a:buffer,
+ \ l:temporary_file,
+ \ a:input,
+ \)
return [l:temporary_file, l:command, l:file_created]
endfunction
diff --git a/autoload/ale/debugging.vim b/autoload/ale/debugging.vim
index 3aed38fe..e4bf5e7e 100644
--- a/autoload/ale/debugging.vim
+++ b/autoload/ale/debugging.vim
@@ -31,6 +31,7 @@ let s:global_variable_list = [
\ 'ale_list_vertical',
\ 'ale_list_window_size',
\ 'ale_loclist_msg_format',
+\ 'ale_lsp_root',
\ 'ale_max_buffer_history_size',
\ 'ale_max_signs',
\ 'ale_maximum_file_size',
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index ace123dc..c3313512 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -74,15 +74,11 @@ function! ale#engine#InitBufferInfo(buffer) abort
" job_list will hold the list of job IDs
" active_linter_list will hold the list of active linter names
" loclist holds the loclist items after all jobs have completed.
- " temporary_file_list holds temporary files to be cleaned up
- " temporary_directory_list holds temporary directories to be cleaned up
let g:ale_buffer_info[a:buffer] = {
\ 'job_list': [],
\ 'active_linter_list': [],
\ 'active_other_sources_list': [],
\ 'loclist': [],
- \ 'temporary_file_list': [],
- \ 'temporary_directory_list': [],
\}
return 1
@@ -104,73 +100,25 @@ endfunction
" Register a temporary file to be managed with the ALE engine for
" a current job run.
function! ale#engine#ManageFile(buffer, filename) abort
- call ale#engine#InitBufferInfo(a:buffer)
- call add(g:ale_buffer_info[a:buffer].temporary_file_list, a:filename)
+ " TODO: Emit deprecation warning here later.
+ call ale#command#ManageFile(a:buffer, a:filename)
endfunction
" Same as the above, but manage an entire directory.
function! ale#engine#ManageDirectory(buffer, directory) abort
- call ale#engine#InitBufferInfo(a:buffer)
- call add(g:ale_buffer_info[a:buffer].temporary_directory_list, a:directory)
+ " TODO: Emit deprecation warning here later.
+ call ale#command#ManageDirectory(a:buffer, a:directory)
endfunction
function! ale#engine#CreateFile(buffer) abort
- " This variable can be set to 1 in tests to stub this out.
- if get(g:, 'ale_create_dummy_temporary_file')
- return 'TEMP'
- endif
-
- let l:temporary_file = ale#util#Tempname()
- call ale#engine#ManageFile(a:buffer, l:temporary_file)
-
- return l:temporary_file
+ " TODO: Emit deprecation warning here later.
+ return ale#command#CreateFile(a:buffer)
endfunction
" Create a new temporary directory and manage it in one go.
function! ale#engine#CreateDirectory(buffer) abort
- " This variable can be set to 1 in tests to stub this out.
- if get(g:, 'ale_create_dummy_temporary_file')
- return 'TEMP_DIR'
- endif
-
- let l:temporary_directory = ale#util#Tempname()
- " Create the temporary directory for the file, unreadable by 'other'
- " users.
- call mkdir(l:temporary_directory, '', 0750)
- call ale#engine#ManageDirectory(a:buffer, l:temporary_directory)
-
- return l:temporary_directory
-endfunction
-
-function! ale#engine#RemoveManagedFiles(buffer) abort
- let l:info = get(g:ale_buffer_info, a:buffer, {})
-
- " We can't delete anything in a sandbox, so wait until we escape from
- " it to delete temporary files and directories.
- if ale#util#InSandbox()
- return
- endif
-
- " Delete files with a call akin to a plan `rm` command.
- if has_key(l:info, 'temporary_file_list')
- for l:filename in l:info.temporary_file_list
- call delete(l:filename)
- endfor
-
- let l:info.temporary_file_list = []
- endif
-
- " Delete directories like `rm -rf`.
- " Directories are handled differently from files, so paths that are
- " intended to be single files can be set up for automatic deletion without
- " accidentally deleting entire directories.
- if has_key(l:info, 'temporary_directory_list')
- for l:directory in l:info.temporary_directory_list
- call delete(l:directory, 'rf')
- endfor
-
- let l:info.temporary_directory_list = []
- endif
+ " TODO: Emit deprecation warning here later.
+ return ale#command#CreateDirectory(a:buffer)
endfunction
function! s:GatherOutput(job_id, line) abort
@@ -321,7 +269,7 @@ function! ale#engine#SetResults(buffer, loclist) abort
" Automatically remove all managed temporary files and directories
" now that all jobs have completed.
- call ale#engine#RemoveManagedFiles(a:buffer)
+ call ale#command#RemoveManagedFiles(a:buffer)
" Call user autocommands. This allows users to hook into ALE's lint cycle.
silent doautocmd <nomodeline> User ALELintPost
@@ -472,26 +420,8 @@ endfunction
" Given part of a command, replace any % with %%, so that no characters in
" the string will be replaced with filenames, etc.
function! ale#engine#EscapeCommandPart(command_part) abort
- return substitute(a:command_part, '%', '%%', 'g')
-endfunction
-
-function! s:CreateTemporaryFileForJob(buffer, temporary_file) abort
- if empty(a:temporary_file)
- " There is no file, so we didn't create anything.
- return 0
- endif
-
- let l:temporary_directory = fnamemodify(a:temporary_file, ':h')
- " Create the temporary directory for the file, unreadable by 'other'
- " users.
- call mkdir(l:temporary_directory, '', 0750)
- " Automatically delete the directory later.
- call ale#engine#ManageDirectory(a:buffer, l:temporary_directory)
- " Write the buffer out to a file.
- let l:lines = getbufline(a:buffer, 1, '$')
- call ale#util#Writefile(a:buffer, l:lines, a:temporary_file)
-
- return 1
+ " TODO: Emit deprecation warning here later.
+ return ale#command#EscapeCommandPart(a:command_part)
endfunction
" Run a job.
@@ -517,7 +447,7 @@ function! s:RunJob(options) abort
\ l:executable,
\ l:command,
\ l:read_buffer,
- \ function('s:CreateTemporaryFileForJob'),
+ \ v:null,
\)
if l:file_created
diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim
index 59502933..b13878eb 100644
--- a/autoload/ale/fix.vim
+++ b/autoload/ale/fix.vim
@@ -66,11 +66,17 @@ function! ale#fix#ApplyQueuedFixes() abort
endfunction
function! ale#fix#ApplyFixes(buffer, output) abort
- call ale#fix#RemoveManagedFiles(a:buffer)
-
let l:data = g:ale_fix_buffer_data[a:buffer]
let l:data.output = a:output
let l:data.changes_made = l:data.lines_before != l:data.output
+ let l:data.done = 1
+
+ call ale#command#RemoveManagedFiles(a:buffer)
+
+ if !bufexists(a:buffer)
+ " Remove the buffer data when it doesn't exist.
+ call remove(g:ale_fix_buffer_data, a:buffer)
+ endif
if l:data.changes_made && bufexists(a:buffer)
let l:lines = getbufline(a:buffer, 1, '$')
@@ -83,13 +89,6 @@ function! ale#fix#ApplyFixes(buffer, output) abort
endif
endif
- if !bufexists(a:buffer)
- " Remove the buffer data when it doesn't exist.
- call remove(g:ale_fix_buffer_data, a:buffer)
- endif
-
- let l:data.done = 1
-
" We can only change the lines of a buffer which is currently open,
" so try and apply the fixes to the current buffer.
call ale#fix#ApplyQueuedFixes()
@@ -146,50 +145,6 @@ function! s:HandleExit(job_id, exit_code) abort
\})
endfunction
-function! ale#fix#ManageDirectory(buffer, directory) abort
- call add(g:ale_fix_buffer_data[a:buffer].temporary_directory_list, a:directory)
-endfunction
-
-function! ale#fix#RemoveManagedFiles(buffer) abort
- if !has_key(g:ale_fix_buffer_data, a:buffer)
- return
- endif
-
- " We can't delete anything in a sandbox, so wait until we escape from
- " it to delete temporary files and directories.
- if ale#util#InSandbox()
- return
- endif
-
- " Delete directories like `rm -rf`.
- " Directories are handled differently from files, so paths that are
- " intended to be single files can be set up for automatic deletion without
- " accidentally deleting entire directories.
- for l:directory in g:ale_fix_buffer_data[a:buffer].temporary_directory_list
- call delete(l:directory, 'rf')
- endfor
-
- let g:ale_fix_buffer_data[a:buffer].temporary_directory_list = []
-endfunction
-
-function! s:CreateTemporaryFileForJob(input, buffer, temporary_file) abort
- if empty(a:temporary_file)
- " There is no file, so we didn't create anything.
- return 0
- endif
-
- let l:temporary_directory = fnamemodify(a:temporary_file, ':h')
- " Create the temporary directory for the file, unreadable by 'other'
- " users.
- call mkdir(l:temporary_directory, '', 0750)
- " Automatically delete the directory later.
- call ale#fix#ManageDirectory(a:buffer, l:temporary_directory)
- " Write the buffer out to a file.
- call ale#util#Writefile(a:buffer, a:input, a:temporary_file)
-
- return 1
-endfunction
-
function! s:RunJob(options) abort
let l:buffer = a:options.buffer
let l:command = a:options.command
@@ -223,7 +178,7 @@ function! s:RunJob(options) abort
\ '',
\ l:command,
\ l:read_buffer,
- \ function('s:CreateTemporaryFileForJob', [l:input]),
+ \ l:input,
\)
let l:command = ale#job#PrepareCommand(l:buffer, l:command)
@@ -469,8 +424,13 @@ function! ale#fix#Fix(buffer, fixing_flag, ...) abort
call ale#job#Stop(l:job_id)
endfor
+ " Mark the buffer as `done` so files can be removed.
+ if has_key(g:ale_fix_buffer_data, a:buffer)
+ let g:ale_fix_buffer_data[a:buffer].done = 1
+ endif
+
" Clean up any files we might have left behind from a previous run.
- call ale#fix#RemoveManagedFiles(a:buffer)
+ call ale#command#RemoveManagedFiles(a:buffer)
call ale#fix#InitBufferData(a:buffer, a:fixing_flag)
silent doautocmd <nomodeline> User ALEFixPre
diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim
index d92dae7e..b029d833 100644
--- a/autoload/ale/lsp_linter.vim
+++ b/autoload/ale/lsp_linter.vim
@@ -152,12 +152,45 @@ function! ale#lsp_linter#GetConfig(buffer, linter) abort
return l:config
endfunction
+function! ale#lsp_linter#FindProjectRoot(buffer, linter) abort
+ let l:buffer_ale_root = getbufvar(a:buffer, 'ale_lsp_root', {})
+
+ if type(l:buffer_ale_root) is v:t_string
+ return l:buffer_ale_root
+ endif
+
+ " Try to get a buffer-local setting for the root
+ if has_key(l:buffer_ale_root, a:linter.name)
+ let l:Root = l:buffer_ale_root[a:linter.name]
+
+ if type(l:Root) is v:t_func
+ return l:Root(a:buffer)
+ else
+ return l:Root
+ endif
+ endif
+
+ " Try to get a global setting for the root
+ if has_key(g:ale_lsp_root, a:linter.name)
+ let l:Root = g:ale_lsp_root[a:linter.name]
+
+ if type(l:Root) is v:t_func
+ return l:Root(a:buffer)
+ else
+ return l:Root
+ endif
+ endif
+
+ " Fall back to the linter-specific configuration
+ return ale#util#GetFunction(a:linter.project_root_callback)(a:buffer)
+endfunction
+
" Given a buffer, an LSP linter, start up an LSP linter and get ready to
" receive messages for the document.
function! ale#lsp_linter#StartLSP(buffer, linter) abort
let l:command = ''
let l:address = ''
- let l:root = ale#util#GetFunction(a:linter.project_root_callback)(a:buffer)
+ let l:root = ale#lsp_linter#FindProjectRoot(a:buffer, a:linter)
if empty(l:root) && a:linter.lsp isnot# 'tsserver'
" If there's no project root, then we can't check files with LSP,
@@ -182,7 +215,7 @@ function! ale#lsp_linter#StartLSP(buffer, linter) abort
let l:command = ale#linter#GetCommand(a:buffer, a:linter)
" Format the command, so %e can be formatted into it.
- let l:command = ale#command#FormatCommand(a:buffer, l:executable, l:command, 0, {-> 0})[1]
+ let l:command = ale#command#FormatCommand(a:buffer, l:executable, l:command, 0, v:false)[1]
let l:command = ale#job#PrepareCommand(a:buffer, l:command)
let l:ready = ale#lsp#StartProgram(l:conn_id, l:executable, l:command)
endif
diff --git a/doc/ale-python.txt b/doc/ale-python.txt
index 3d355bc6..175216f6 100644
--- a/doc/ale-python.txt
+++ b/doc/ale-python.txt
@@ -66,6 +66,45 @@ g:ale_python_autopep8_use_global *g:ale_python_autopep8_use_global*
===============================================================================
+bandit *ale-python-bandit*
+
+g:ale_python_bandit_executable *g:ale_python_bandit_executable*
+ *b:ale_python_bandit_executable*
+ Type: |String|
+ Default: `'bandit'`
+
+ See |ale-integrations-local-executables|
+
+ Set this to `'pipenv'` to invoke `'pipenv` `run` `bandit'`.
+
+
+g:ale_python_bandit_options *g:ale_python_bandit_options*
+ *b:ale_python_bandit_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be changed to add command-line arguments to the
+ bandit invocation.
+
+
+g:ale_python_bandit_use_global *g:ale_python_bandit_use_global*
+ *b:ale_python_bandit_use_global*
+ Type: |Number|
+ Default: `get(g:, 'ale_use_global_executables', 0)`
+
+ See |ale-integrations-local-executables|
+
+
+g:ale_python_bandit_auto_pipenv *g:ale_python_bandit_auto_pipenv*
+ *b:ale_python_bandit_auto_pipenv*
+ Type: |Number|
+ Default: `0`
+
+ Detect whether the file is inside a pipenv, and set the executable to `pipenv`
+ if true. This is overridden by a manually-set executable.
+
+
+===============================================================================
black *ale-python-black*
g:ale_python_black_executable *g:ale_python_black_executable*
diff --git a/doc/ale.txt b/doc/ale.txt
index ac71ab83..3a75273a 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -257,6 +257,7 @@ CONTENTS *ale-contents*
cython..............................|ale-pyrex-cython|
python................................|ale-python-options|
autopep8............................|ale-python-autopep8|
+ bandit..............................|ale-python-bandit|
black...............................|ale-python-black|
flake8..............................|ale-python-flake8|
isort...............................|ale-python-isort|
@@ -453,7 +454,7 @@ Notes:
* Idris: `idris`
* ISPC: `ispc`!!
* Java: `checkstyle`, `javac`, `google-java-format`, `PMD`, `javalsp`, `uncrustify`
-* JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint`, `prettier-standard`, `standard`, `xo`
+* JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint`, `prettier-standard`, `standard`, `tsserver`, `xo`
* JSON: `fixjson`, `jsonlint`, `jq`, `prettier`
* Julia: `languageserver`
* Kotlin: `kotlinc`!!, `ktlint`!!, `languageserver`
@@ -484,7 +485,7 @@ Notes:
* proto: `protoc-gen-lint`
* Pug: `pug-lint`
* Puppet: `languageserver`, `puppet`, `puppet-lint`
-* Python: `autopep8`, `black`, `flake8`, `isort`, `mypy`, `prospector`, `pycodestyle`, `pydocstyle`, `pyls`, `pyre`, `pylint`!!, `vulture`!!, `yapf`
+* Python: `autopep8`, `bandit`, `black`, `flake8`, `isort`, `mypy`, `prospector`, `pycodestyle`, `pydocstyle`, `pyls`, `pyre`, `pylint`!!, `vulture`!!, `yapf`
* QML: `qmlfmt`, `qmllint`
* R: `lintr`
* Racket: `raco`
@@ -1572,6 +1573,22 @@ b:ale_loclist_msg_format *b:ale_loclist_msg_format*
The strings for configuring `%severity%` are also used for this option.
+g:ale_lsp_root *g:ale_lsp_root*
+b:ale_lsp_root *b:ale_lsp_root*
+
+ Type: |Dictionary| or |String|
+ Default: {}
+
+ This option is used to determine the project root for the LSP linter. If the
+ value is a |Dictionary|, it maps a linter to either a string containing the
+ project root or a |Funcref| to call to look up the root. The funcref is
+ provided the buffer number as its argument.
+
+ The buffer-specific variable may additionally be a string containing the
+ project root itself.
+
+ If neither variable yields a result, a linter-specific function is invoked to
+ detect a project root. If this, too, yields no result, the linter is disabled.
g:ale_max_buffer_history_size *g:ale_max_buffer_history_size*
@@ -2598,26 +2615,26 @@ ale#Queue(delay, [linting_flag, buffer_number]) *ale#Queue()*
is broken, or when developing ALE itself.
-ale#engine#CreateDirectory(buffer) *ale#engine#CreateDirectory()*
+ale#command#CreateDirectory(buffer) *ale#command#CreateDirectory()*
Create a new temporary directory with a unique name, and manage that
- directory with |ale#engine#ManageDirectory()|, so it will be removed as soon
+ directory with |ale#command#ManageDirectory()|, so it will be removed as soon
as possible.
It is advised to only call this function from a callback function for
returning a linter command to run.
-ale#engine#CreateFile(buffer) *ale#engine#CreateFile()*
+ale#command#CreateFile(buffer) *ale#command#CreateFile()*
Create a new temporary file with a unique name, and manage that file with
- |ale#engine#ManageFile()|, so it will be removed as soon as possible.
+ |ale#command#ManageFile()|, so it will be removed as soon as possible.
It is advised to only call this function from a callback function for
returning a linter command to run.
-ale#engine#EscapeCommandPart(command_part) *ale#engine#EscapeCommandPart()*
+ale#command#EscapeCommandPart(command_part) *ale#command#EscapeCommandPart()*
Given a |String|, return a |String| with all `%` characters replaced with
`%%` instead. This function can be used to escape strings which are
@@ -2626,23 +2643,7 @@ ale#engine#EscapeCommandPart(command_part) *ale#engine#EscapeCommandPart()*
specially.
-ale#engine#GetLoclist(buffer) *ale#engine#GetLoclist()*
-
- Given a buffer number, this function will return the list of problems
- reported by ALE for a given buffer in the format accepted by |setqflist()|.
-
- A reference to the buffer's list of problems will be returned. The list must
- be copied before applying |map()| or |filter()|.
-
-
-ale#engine#IsCheckingBuffer(buffer) *ale#engine#IsCheckingBuffer()*
-
- Given a buffer number, returns `1` when ALE is busy checking that buffer.
-
- This function can be used for status lines, tab names, etc.
-
-
-ale#engine#ManageFile(buffer, filename) *ale#engine#ManageFile()*
+ale#command#ManageFile(buffer, filename) *ale#command#ManageFile()*
Given a buffer number for a buffer currently running some linting tasks
and a filename, register a filename with ALE for automatic deletion after
@@ -2657,20 +2658,36 @@ ale#engine#ManageFile(buffer, filename) *ale#engine#ManageFile()*
files and symlinks given to this function. This is to prevent entire
directories from being accidentally deleted, say in cases of writing
`dir . '/' . filename` where `filename` is actually `''`, etc. ALE instead
- manages directories separetly with the |ale#engine#ManageDirectory| function.
+ manages directories separetly with the |ale#command#ManageDirectory| function.
-ale#engine#ManageDirectory(buffer, directory) *ale#engine#ManageDirectory()*
+ale#command#ManageDirectory(buffer, directory) *ale#command#ManageDirectory()*
- Like |ale#engine#ManageFile()|, but directories and all of their contents
+ Like |ale#command#ManageFile()|, but directories and all of their contents
will be deleted, akin to `rm -rf directory`, which could lead to loss of
data if mistakes are made. This command will also delete any temporary
filenames given to it.
- It is advised to use |ale#engine#ManageFile()| instead for deleting single
+ It is advised to use |ale#command#ManageFile()| instead for deleting single
files.
+ale#engine#GetLoclist(buffer) *ale#engine#GetLoclist()*
+
+ Given a buffer number, this function will return the list of problems
+ reported by ALE for a given buffer in the format accepted by |setqflist()|.
+
+ A reference to the buffer's list of problems will be returned. The list must
+ be copied before applying |map()| or |filter()|.
+
+
+ale#engine#IsCheckingBuffer(buffer) *ale#engine#IsCheckingBuffer()*
+
+ Given a buffer number, returns `1` when ALE is busy checking that buffer.
+
+ This function can be used for status lines, tab names, etc.
+
+
ale#fix#registry#Add(name, func, filetypes, desc, [aliases])
*ale#fix#registry#Add()*
diff --git a/plugin/ale.vim b/plugin/ale.vim
index 7d6a48f0..416324bc 100644
--- a/plugin/ale.vim
+++ b/plugin/ale.vim
@@ -87,6 +87,9 @@ let g:ale_lint_on_save = get(g:, 'ale_lint_on_save', 1)
" This flag can be set to 1 to enable linting when the filetype is changed.
let g:ale_lint_on_filetype_changed = get(g:, 'ale_lint_on_filetype_changed', 1)
+" This Dictionary configures the default LSP roots for various linters.
+let g:ale_lsp_root = get(g:, 'ale_lsp_root', {})
+
" This flag can be set to 1 to enable automatically fixing files on save.
let g:ale_fix_on_save = get(g:, 'ale_fix_on_save', 0)
diff --git a/test/command_callback/test_bandit_command_callback.vader b/test/command_callback/test_bandit_command_callback.vader
new file mode 100644
index 00000000..5d1e6fd3
--- /dev/null
+++ b/test/command_callback/test_bandit_command_callback.vader
@@ -0,0 +1,49 @@
+Before:
+ call ale#assert#SetUpLinterTest('python', 'bandit')
+ let b:bandit_flags = ' --format custom '
+ \ . '--msg-template "{line}:{test_id}:{severity}:{msg}" '
+
+After:
+ call ale#assert#TearDownLinterTest()
+ unlet! b:bandit_flags
+
+Execute(The bandit command callback should return default string):
+ AssertLinter 'bandit',
+ \ ale#Escape('bandit')
+ \ . b:bandit_flags
+ \ . ' -'
+
+Execute(The bandit command callback should allow options):
+ let g:ale_python_bandit_options = '--configfile bandit.yaml'
+
+ AssertLinter 'bandit',
+ \ ale#Escape('bandit')
+ \ . b:bandit_flags
+ \ . ' --configfile bandit.yaml -'
+
+Execute(The bandit executable should be configurable):
+ let g:ale_python_bandit_executable = '~/.local/bin/bandit'
+
+ AssertLinter '~/.local/bin/bandit',
+ \ ale#Escape('~/.local/bin/bandit')
+ \ . b:bandit_flags
+ \ . ' -'
+
+Execute(Setting executable to 'pipenv' appends 'run bandit'):
+ let g:ale_python_bandit_executable = 'path/to/pipenv'
+
+ AssertLinter 'path/to/pipenv',
+ \ ale#Escape('path/to/pipenv')
+ \ . ' run bandit'
+ \ . b:bandit_flags
+ \ . ' -'
+
+Execute(Pipenv is detected when python_bandit_auto_pipenv is set):
+ let g:ale_python_bandit_auto_pipenv = 1
+ call ale#test#SetFilename('/testplugin/test/python_fixtures/pipenv/whatever.py')
+
+ AssertLinter 'pipenv',
+ \ ale#Escape('pipenv')
+ \ . ' run bandit'
+ \ . b:bandit_flags
+ \ . ' -'
diff --git a/test/handler/test_bandit_handler.vader b/test/handler/test_bandit_handler.vader
new file mode 100644
index 00000000..a2793a46
--- /dev/null
+++ b/test/handler/test_bandit_handler.vader
@@ -0,0 +1,42 @@
+Before:
+ runtime ale_linters/python/bandit.vim
+
+After:
+ call ale#linter#Reset()
+
+Execute(The bandit handler for Python should parse input correctly):
+ AssertEqual
+ \ [
+ \ {
+ \ 'bufnr': 0,
+ \ 'lnum': 2,
+ \ 'code': 'B404',
+ \ 'type': 'I',
+ \ 'text': 'Consider possible security implications associated with subprocess module.',
+ \ },
+ \ {
+ \ 'bufnr': 0,
+ \ 'lnum': 4,
+ \ 'code': 'B305',
+ \ 'type': 'W',
+ \ 'text': 'Use of insecure cipher mode cryptography.hazmat.primitives.ciphers.modes.ECB.',
+ \ },
+ \ {
+ \ 'bufnr': 0,
+ \ 'lnum': 6,
+ \ 'code': 'B609',
+ \ 'type': 'E',
+ \ 'text': 'Possible wildcard injection in call: subprocess.Popen',
+ \ },
+ \ ],
+ \ ale_linters#python#bandit#Handle(0, [
+ \ '[main] INFO profile include tests: None',
+ \ '[main] INFO profile exclude tests: None',
+ \ '[main] INFO cli include tests: None',
+ \ '[main] INFO cli exclude tests: None',
+ \ '[main] INFO running on Python 3.7.2',
+ \ '[node_visitor] INFO Unable to find qualified name for module: <stdin>',
+ \ '2:B404:LOW:Consider possible security implications associated with subprocess module.',
+ \ '4:B305:MEDIUM:Use of insecure cipher mode cryptography.hazmat.primitives.ciphers.modes.ECB.',
+ \ '6:B609:HIGH:Possible wildcard injection in call: subprocess.Popen',
+ \ ])
diff --git a/test/lsp/test_lsp_command_formatting.vader b/test/lsp/test_lsp_command_formatting.vader
index 9721f37f..fcd4f78c 100644
--- a/test/lsp/test_lsp_command_formatting.vader
+++ b/test/lsp/test_lsp_command_formatting.vader
@@ -17,6 +17,7 @@ Execute(Command formatting should be applied correctly for LSP linters):
call ale#lsp_linter#StartLSP(
\ bufnr(''),
\ {
+ \ 'name': 'linter',
\ 'language_callback': {-> 'x'},
\ 'project_root_callback': {-> '/foo/bar'},
\ 'lsp': 'stdio',
diff --git a/test/lsp/test_lsp_root_detection.vader b/test/lsp/test_lsp_root_detection.vader
new file mode 100644
index 00000000..2575a62c
--- /dev/null
+++ b/test/lsp/test_lsp_root_detection.vader
@@ -0,0 +1,63 @@
+Before:
+ call ale#assert#SetUpLinterTest('c', 'clangd')
+
+ function! Hook1(buffer)
+ return 'abc123'
+ endfunction
+
+After:
+ let g:ale_lsp_root = {}
+ unlet! b:ale_lsp_root
+ delfunction Hook1
+
+ call ale#assert#TearDownLinterTest()
+
+Execute(The buffer-specific variable can be a string):
+ let b:ale_lsp_root = '/some/path'
+ call ale#test#SetFilename('other-file.c')
+
+ AssertLSPProjectFull '/some/path'
+
+Execute(The buffer-specific variable can be a dictionary):
+ let b:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
+ call ale#test#SetFilename('other-file.c')
+
+ AssertLSPProjectFull '/some/path'
+
+Execute(The buffer-specific variable can have funcrefs):
+ let b:ale_lsp_root = {'clangd': function('Hook1'), 'golangserver': '/path'}
+ call ale#test#SetFilename('other-file.c')
+
+ AssertLSPProjectFull 'abc123'
+
+Execute(The global variable can be a dictionary):
+ let g:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
+ call ale#test#SetFilename('other-file.c')
+
+ AssertLSPProjectFull '/some/path'
+
+Execute(The global variable can have funcrefs):
+ let g:ale_lsp_root = {'clangd': function('Hook1'), 'golangserver': '/path'}
+ call ale#test#SetFilename('other-file.c')
+
+ AssertLSPProjectFull 'abc123'
+
+Execute(The buffer-specific variable overrides the global variable):
+ let b:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
+ let g:ale_lsp_root = {'clangd': '/not/this/path', 'golangserver': '/elsewhere'}
+ call ale#test#SetFilename('other-file.c')
+
+ AssertLSPProjectFull '/some/path'
+
+Execute(The global variable is queried if the buffer-specific has no value):
+ let b:ale_lsp_root = {'golangserver': '/other/path'}
+ let g:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/elsewhere'}
+ call ale#test#SetFilename('other-file.c')
+
+ AssertLSPProjectFull '/some/path'
+
+
+Execute(The default hook value is acceptable):
+ call ale#test#SetFilename('other-file.c')
+
+ AssertLSPProjectFull ''
diff --git a/test/test_ale_info.vader b/test/test_ale_info.vader
index 325c2aa8..29c19b8e 100644
--- a/test/test_ale_info.vader
+++ b/test/test_ale_info.vader
@@ -97,6 +97,7 @@ Before:
\ 'let g:ale_list_vertical = 0',
\ 'let g:ale_list_window_size = 10',
\ 'let g:ale_loclist_msg_format = ''%code: %%s''',
+ \ 'let g:ale_lsp_root = {}',
\ 'let g:ale_max_buffer_history_size = 20',
\ 'let g:ale_max_signs = -1',
\ 'let g:ale_maximum_file_size = 0',
diff --git a/test/test_format_command.vader b/test/test_format_command.vader
index 119c7138..15435326 100644
--- a/test/test_format_command.vader
+++ b/test/test_format_command.vader
@@ -8,7 +8,9 @@ Before:
AssertEqual 'dummy.txt', fnamemodify(a:filename, ':t')
endfunction
- function! TestCreateFunc(buffer, temporary_file) abort
+ runtime autoload/ale/command.vim
+
+ function! ale#command#CreateTempFile(buffer, temporary_file, input) abort
return !empty(a:temporary_file)
endfunction
@@ -17,17 +19,18 @@ After:
unlet! g:match
delfunction CheckTempFile
- delfunction TestCreateFunc
+
+ runtime autoload/ale/command.vim
Execute(FormatCommand should do nothing to basic command strings):
AssertEqual
\ ['', 'awesome-linter do something', 0],
- \ ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0, function('TestCreateFunc'))
+ \ ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0, v:null)
Execute(FormatCommand should handle %%, and ignore other percents):
AssertEqual
\ ['', '% %%d %%f %x %', 0],
- \ ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0, function('TestCreateFunc'))
+ \ ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0, v:null)
Execute(FormatCommand should convert %s to the current filename):
AssertEqual
@@ -36,10 +39,10 @@ Execute(FormatCommand should convert %s to the current filename):
\ 'foo ' . ale#Escape(expand('%:p')) . ' bar ' . ale#Escape(expand('%:p')),
\ 0,
\ ],
- \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0, function('TestCreateFunc'))
+ \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0, v:null)
Execute(FormatCommand should convert %t to a new temporary filename):
- let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, function('TestCreateFunc'))
+ let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, v:null)
call CheckTempFile(g:result[0])
@@ -52,17 +55,22 @@ Execute(FormatCommand should convert %t to a new temporary filename):
" The two temporary filenames formatted in should be the same.
AssertEqual g:match[1], g:match[2]
+Execute(FormatCommand should not convert %t to a new temporary filename when the input is given as v:false):
+ let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, v:false)
+
+ AssertEqual ['', 'foo %t bar %t', 0], g:result
+
Execute(FormatCommand should signal that files are created when temporary files are needed):
AssertEqual
\ 1,
- \ ale#command#FormatCommand(bufnr('%'), '', 'foo %t', 0, function('TestCreateFunc'))[2]
+ \ ale#command#FormatCommand(bufnr('%'), '', 'foo %t', 0, v:null)[2]
AssertEqual
\ 0,
- \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s', 0, function('TestCreateFunc'))[2]
+ \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s', 0, v:null)[2]
Execute(FormatCommand should let you combine %s and %t):
- let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0, function('TestCreateFunc'))
+ let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0, v:null)
call CheckTempFile(g:result[0])
@@ -79,30 +87,30 @@ Execute(FormatCommand should replace %e with the escaped executable):
if has('win32')
AssertEqual
\ ['', 'foo foo', 0],
- \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc'))
+ \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, v:null)
AssertEqual
\ ['', '"foo bar"', 0],
- \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc'))
+ \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, v:null)
AssertEqual
\ ['', '%e %e', 0],
- \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc'))
+ \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, v:null)
else
AssertEqual
\ ['', '''foo'' ''foo''', 0],
- \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc'))
+ \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, v:null)
AssertEqual
\ ['', '''foo bar''', 0],
- \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc'))
+ \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, v:null)
AssertEqual
\ ['', '%e %e', 0],
- \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc'))
+ \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, v:null)
endif
Execute(EscapeCommandPart should escape all percent signs):
AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%')
Execute(EscapeCommandPart should pipe in temporary files appropriately):
- let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar', 1, function('TestCreateFunc'))
+ let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar', 1, v:null)
call CheckTempFile(g:result[0])
@@ -110,7 +118,7 @@ Execute(EscapeCommandPart should pipe in temporary files appropriately):
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
AssertEqual ale#Escape(g:result[0]), g:match[1]
- let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar %t', 1, function('TestCreateFunc'))
+ let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar %t', 1, v:null)
call CheckTempFile(g:result[0])
diff --git a/test/test_sandbox_execution.vader b/test/test_sandbox_execution.vader
index 5a4974ba..cf994ce8 100644
--- a/test/test_sandbox_execution.vader
+++ b/test/test_sandbox_execution.vader
@@ -59,7 +59,7 @@ Execute(ALE shouldn't blow up if file cleanup happens in a sandbox):
\ 'temporary_file_list': ['/tmp/foo'],
\ 'temporary_directory_list': ['/tmp/bar'],
\}
- sandbox call ale#engine#RemoveManagedFiles(3)
+ sandbox call ale#command#RemoveManagedFiles(3)
AssertEqual ['/tmp/foo'], g:ale_buffer_info[3].temporary_file_list
AssertEqual ['/tmp/bar'], g:ale_buffer_info[3].temporary_directory_list
diff --git a/test/test_temporary_file_management.vader b/test/test_temporary_file_management.vader
index 4847706a..b25da7ac 100644
--- a/test/test_temporary_file_management.vader
+++ b/test/test_temporary_file_management.vader
@@ -13,21 +13,21 @@ Before:
" We are registering a temporary file, so we should delete it.
let g:filename = tempname()
call writefile(['foo'], g:filename)
- call ale#engine#ManageFile(a:buffer, g:filename)
+ call ale#command#ManageFile(a:buffer, g:filename)
" We are registering this directory appropriately, so we should delete
" the whole thing.
let g:directory = tempname()
call mkdir(g:directory)
call writefile(['foo'], g:directory . '/bar')
- call ale#engine#ManageDirectory(a:buffer, g:directory)
+ call ale#command#ManageDirectory(a:buffer, g:directory)
" We are registering this directory as temporary file, so we
" shouldn't delete it.
let g:preserved_directory = tempname()
call mkdir(g:preserved_directory)
call writefile(['foo'], g:preserved_directory . '/bar')
- call ale#engine#ManageFile(a:buffer, g:preserved_directory)
+ call ale#command#ManageFile(a:buffer, g:preserved_directory)
return g:command
endfunction
@@ -42,6 +42,7 @@ Before:
\ 'callback': 'TestCallback',
\ 'command_callback': 'TestCommandCallback',
\})
+ call ale#command#ClearData()
After:
Restore
@@ -58,6 +59,7 @@ After:
delfunction TestCommandCallback
delfunction TestCallback
call ale#linter#Reset()
+ call ale#command#ClearData()
Given foobar (Some imaginary filetype):
foo
@@ -95,11 +97,11 @@ Execute(ALE should delete managed files when the buffer is removed):
Assert !isdirectory(g:directory), 'The temporary directory was not deleted'
Assert isdirectory(g:preserved_directory), 'The tempoary directory was not kept'
-Execute(ALE should create and delete directories for ale#engine#CreateDirectory()):
+Execute(ALE should create and delete directories for ale#command#CreateDirectory()):
call ale#engine#InitBufferInfo(bufnr('%'))
- let b:dir = ale#engine#CreateDirectory(bufnr('%'))
- let b:dir2 = ale#engine#CreateDirectory(bufnr('%'))
+ let b:dir = ale#command#CreateDirectory(bufnr('%'))
+ let b:dir2 = ale#command#CreateDirectory(bufnr('%'))
Assert isdirectory(b:dir), 'The directory was not created'
@@ -117,16 +119,26 @@ Execute(ALE should create and delete directories for ale#engine#CreateDirectory(
Assert !isdirectory(b:dir), 'The directory was not deleted'
Assert !isdirectory(b:dir2), 'The second directory was not deleted'
-Execute(ale#engine#ManageFile should add the file even if the buffer info hasn't be set yet):
- let g:ale_buffer_info = {}
- call ale#engine#ManageFile(bufnr(''), '/foo/bar')
+Execute(ale#command#ManageFile should add the file even if the buffer info hasn't be set yet):
+ call ale#command#ManageFile(bufnr(''), '/foo/bar')
+
AssertEqual
- \ ['/foo/bar'],
- \ g:ale_buffer_info[bufnr('')].temporary_file_list
+ \ {
+ \ bufnr(''): {
+ \ 'file_list': ['/foo/bar'],
+ \ 'directory_list': [],
+ \ },
+ \ },
+ \ ale#command#GetData()
+
+Execute(ale#command#ManageDirectory should add the directory even if the buffer info hasn't be set yet):
+ call ale#command#ManageDirectory(bufnr(''), '/foo/bar')
-Execute(ale#engine#ManageDirectory should add the directory even if the buffer info hasn't be set yet):
- let g:ale_buffer_info = {}
- call ale#engine#ManageDirectory(bufnr(''), '/foo/bar')
AssertEqual
- \ ['/foo/bar'],
- \ g:ale_buffer_info[bufnr('')].temporary_directory_list
+ \ {
+ \ bufnr(''): {
+ \ 'file_list': [],
+ \ 'directory_list': ['/foo/bar'],
+ \ },
+ \ },
+ \ ale#command#GetData()