Replace every stdin-wrapper script with the new %t formatting support

This commit is contained in:
w0rp 2017-02-11 19:40:57 +00:00
parent c33602534e
commit ecbb276805
39 changed files with 103 additions and 208 deletions

View File

@ -4,6 +4,6 @@
call ale#linter#Define('ansible', {
\ 'name': 'ansible',
\ 'executable': 'ansible',
\ 'command': g:ale#util#stdin_wrapper . ' .yml ansible-lint -p',
\ 'command': 'ansible-lint -p %t',
\ 'callback': 'ale#handlers#HandlePEP8Format',
\})

View File

@ -2,15 +2,14 @@
" Description: cppcheck linter for c files
" Set this option to change the cppcheck options
if !exists('g:ale_c_cppcheck_options')
let g:ale_c_cppcheck_options = '--enable=style'
endif
let g:ale_c_cppcheck_options = get(g:, 'ale_c_cppcheck_options', '--enable=style')
call ale#linter#Define('c', {
\ 'name': 'cppcheck',
\ 'output_stream': 'both',
\ 'executable': 'cppcheck',
\ 'command': g:ale#util#stdin_wrapper . ' .c cppcheck -q --language=c '
\ . g:ale_c_cppcheck_options,
\ 'command': 'cppcheck -q --language=c '
\ . g:ale_c_cppcheck_options
\ . ' %t',
\ 'callback': 'ale#handlers#HandleCppCheckFormat',
\})

View File

@ -35,7 +35,7 @@ endfunction
call ale#linter#Define('chef', {
\ 'name': 'foodcritic',
\ 'executable': 'foodcritic',
\ 'command': g:ale#util#stdin_wrapper . ' .rb foodcritic',
\ 'command': 'foodcritic %t',
\ 'callback': 'ale_linters#chef#foodcritic#Handle',
\})

View File

@ -2,15 +2,14 @@
" Description: cppcheck linter for cpp files
" Set this option to change the cppcheck options
if !exists('g:ale_cpp_cppcheck_options')
let g:ale_cpp_cppcheck_options = '--enable=style'
endif
let g:ale_cpp_cppcheck_options = get(g:, 'ale_cpp_cppcheck_options', '--enable=style')
call ale#linter#Define('cpp', {
\ 'name': 'cppcheck',
\ 'output_stream': 'both',
\ 'executable': 'cppcheck',
\ 'command': g:ale#util#stdin_wrapper . ' .cpp cppcheck -q --language=c++ '
\ . g:ale_cpp_cppcheck_options,
\ 'command': 'cppcheck -q --language=c++ '
\ . g:ale_cpp_cppcheck_options
\ . ' %t',
\ 'callback': 'ale#handlers#HandleCppCheckFormat',
\})

View File

@ -1,6 +1,8 @@
if !exists('g:ale_cs_mcs_options')
let g:ale_cs_mcs_options = ''
endif
let g:ale_cs_mcs_options = get(g:, 'ale_cs_mcs_options', '')
function! ale_linters#cs#mcs#GetCommand(buffer) abort
return 'mcs -unsafe --parse ' . g:ale_cs_mcs_options . ' %t'
endfunction
function! ale_linters#cs#mcs#Handle(buffer, lines) abort
" Look for lines like the following.
@ -31,10 +33,9 @@ function! ale_linters#cs#mcs#Handle(buffer, lines) abort
endfunction
call ale#linter#Define('cs',{
\ 'name': 'mcs',
\ 'output_stream': 'stderr',
\ 'executable': 'mcs',
\ 'command': g:ale#util#stdin_wrapper . ' .cs mcs -unsafe --parse' . g:ale_cs_mcs_options,
\ 'callback': 'ale_linters#cs#mcs#Handle',
\ })
\ 'name': 'mcs',
\ 'output_stream': 'stderr',
\ 'executable': 'mcs',
\ 'command_callback': 'ale_linters#cs#mcs#GetCommand',
\ 'callback': 'ale_linters#cs#mcs#Handle',
\})

View File

@ -4,6 +4,6 @@
call ale#linter#Define('css', {
\ 'name': 'csslint',
\ 'executable': 'csslint',
\ 'command': g:ale#util#stdin_wrapper . ' .css csslint --format=compact',
\ 'command': 'csslint --format=compact %t',
\ 'callback': 'ale#handlers#HandleCSSLintFormat',
\})

View File

@ -46,9 +46,7 @@ function! ale_linters#d#dmd#DMDCommand(buffer, dub_output) abort
endif
endfor
return g:ale#util#stdin_wrapper . ' .d dmd '
\ . join(l:import_list)
\ . ' -o- -vcolumns -c'
return 'dmd '. join(l:import_list) . ' -o- -vcolumns -c %t'
endfunction
function! ale_linters#d#dmd#Handle(buffer, lines) abort

View File

@ -52,9 +52,8 @@ function! ale_linters#elm#make#GetCommand(buffer) abort
" which is why this is hard coded here.
" Source: https://github.com/elm-lang/elm-make/blob/master/src/Flags.hs
let l:elm_cmd = 'elm-make --report=json --output='.shellescape('/dev/null')
let l:stdin_wrapper = g:ale#util#stdin_wrapper . ' .elm'
return l:dir_set_cmd . ' ' . l:stdin_wrapper . ' ' . l:elm_cmd
return l:dir_set_cmd . ' ' . l:elm_cmd . ' %t'
endfunction
call ale#linter#Define('elm', {

View File

@ -3,7 +3,7 @@
let g:ale_erlang_erlc_options = get(g:, 'ale_erlang_erlc_options', '')
function! ale_linters#erlang#erlc#GetCommand(buffer) abort
return g:ale#util#stdin_wrapper . ' .erl erlc ' . g:ale_erlang_erlc_options
return 'erlc ' . g:ale_erlang_erlc_options . ' %t'
endfunction
function! ale_linters#erlang#erlc#Handle(buffer, lines) abort

View File

@ -5,6 +5,6 @@ call ale#linter#Define('go', {
\ 'name': 'gofmt',
\ 'output_stream': 'stderr',
\ 'executable': 'gofmt',
\ 'command': g:ale#util#stdin_wrapper . ' .go gofmt -e',
\ 'command': 'gofmt -e %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\})

View File

@ -4,6 +4,6 @@
call ale#linter#Define('go', {
\ 'name': 'golint',
\ 'executable': 'golint',
\ 'command': g:ale#util#stdin_wrapper . ' .go golint',
\ 'command': 'golint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\})

View File

@ -5,6 +5,6 @@ call ale#linter#Define('go', {
\ 'name': 'go vet',
\ 'output_stream': 'stderr',
\ 'executable': 'go',
\ 'command': g:ale#util#stdin_wrapper . ' .go go vet',
\ 'command': 'go vet %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\})

View File

@ -60,7 +60,7 @@ call ale#linter#Define('haskell', {
\ 'name': 'ghc',
\ 'output_stream': 'stderr',
\ 'executable': 'ghc',
\ 'command': g:ale#util#stdin_wrapper . ' .hs ghc -fno-code -v0',
\ 'command': 'ghc -fno-code -v0 %t',
\ 'callback': 'ale_linters#haskell#ghc#Handle',
\})
@ -68,6 +68,6 @@ call ale#linter#Define('haskell', {
\ 'name': 'stack-ghc',
\ 'output_stream': 'stderr',
\ 'executable': 'stack',
\ 'command': g:ale#util#stdin_wrapper . ' .hs stack ghc -- -fno-code -v0',
\ 'command': 'stack ghc -- -fno-code -v0 %t',
\ 'callback': 'ale_linters#haskell#ghc#Handle',
\})

View File

@ -23,9 +23,9 @@ function! ale_linters#html#htmlhint#GetExecutable(buffer) abort
endfunction
function! ale_linters#html#htmlhint#GetCommand(buffer) abort
return g:ale#util#stdin_wrapper . ' .html '
\ . ale_linters#html#htmlhint#GetExecutable(a:buffer)
return ale_linters#html#htmlhint#GetExecutable(a:buffer)
\ . ' ' . g:ale_html_htmlhint_options
\ . ' %t'
endfunction
call ale#linter#Define('html', {

View File

@ -4,6 +4,6 @@
call ale#linter#Define('markdown', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': g:ale#util#stdin_wrapper . ' .md proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\})

View File

@ -4,6 +4,16 @@
let g:ale_matlab_mlint_executable =
\ get(g:, 'ale_matlab_mlint_executable', 'mlint')
function! ale_linters#matlab#mlint#GetExecutable(buffer) abort
return g:ale_matlab_mlint_executable
endfunction
function! ale_linters#matlab#mlint#GetCommand(buffer) abort
let l:executable = ale_linters#matlab#mlint#GetExecutable(a:buffer)
return l:executable . ' -id %t'
endfunction
function! ale_linters#matlab#mlint#Handle(buffer, lines) abort
" Matches patterns like the following:
"
@ -47,9 +57,8 @@ endfunction
call ale#linter#Define('matlab', {
\ 'name': 'mlint',
\ 'executable': 'mlint',
\ 'command': g:ale#util#stdin_wrapper .
\ ' .m ' . g:ale_matlab_mlint_executable . ' -id',
\ 'executable_callback': 'ale_linters#matlab#mlint#GetExecutable',
\ 'command_callback': 'ale_linters#matlab#mlint#GetCommand',
\ 'output_stream': 'stderr',
\ 'callback': 'ale_linters#matlab#mlint#Handle',
\})

View File

@ -36,6 +36,6 @@ endfunction
call ale#linter#Define('php', {
\ 'name': 'phpmd',
\ 'executable': 'phpmd',
\ 'command': g:ale#util#stdin_wrapper . ' .php phpmd %s text ' . g:ale_php_phpmd_ruleset . ' --ignore-violations-on-exit',
\ 'command': 'phpmd %s text ' . g:ale_php_phpmd_ruleset . ' --ignore-violations-on-exit %t',
\ 'callback': 'ale_linters#php#phpmd#Handle',
\})

View File

@ -5,6 +5,6 @@ call ale#linter#Define('pug', {
\ 'name': 'puglint',
\ 'executable': 'pug-lint',
\ 'output_stream': 'stderr',
\ 'command': g:ale#util#stdin_wrapper . ' .pug pug-lint -r inline',
\ 'command': 'pug-lint -r inline %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\})

View File

@ -33,6 +33,6 @@ call ale#linter#Define('puppet', {
\ 'name': 'puppet',
\ 'executable': 'puppet',
\ 'output_stream': 'stderr',
\ 'command': g:ale#util#stdin_wrapper . ' .pp puppet parser validate --color=false',
\ 'command': 'puppet parser validate --color=false %t',
\ 'callback': 'ale_linters#puppet#puppet#Handle',
\})

View File

@ -3,6 +3,8 @@
call ale#linter#Define('puppet', {
\ 'name': 'puppetlint',
\ 'executable': 'puppet-lint',
\ 'command': g:ale#util#stdin_wrapper . ' .pp puppet-lint --no-autoloader_layout-check --log-format "-:%{line}:%{column}: %{kind}: [%{check}] %{message}"',
\ 'command': 'puppet-lint --no-autoloader_layout-check'
\ . ' --log-format "-:%{line}:%{column}: %{kind}: [%{check}] %{message}"'
\ . ' %t',
\ 'callback': 'ale#handlers#HandleGCCFormat',
\})

View File

@ -5,8 +5,6 @@ call ale#linter#Define('pyrex', {
\ 'name': 'cython',
\ 'output_stream': 'stderr',
\ 'executable': 'cython',
\ 'command': g:ale#util#stdin_wrapper
\ . ' .pyx cython --warning-extra -o '
\ . g:ale#util#nul_file,
\ 'command': 'cython --warning-extra -o ' . g:ale#util#nul_file . ' %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\})

View File

@ -10,10 +10,9 @@ function! g:ale_linters#python#mypy#GetCommand(buffer) abort
\ ? 'MYPYPATH=' . l:automatic_stubs_dir . ' '
\ : ''
return l:automatic_stubs_command
\ . g:ale#util#stdin_wrapper
\ . ' .py mypy --show-column-numbers '
return 'mypy --show-column-numbers '
\ . g:ale_python_mypy_options
\ . ' %t'
endfunction
let s:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+'

View File

@ -12,10 +12,10 @@ function! ale_linters#python#pylint#GetExecutable(buffer) abort
endfunction
function! ale_linters#python#pylint#GetCommand(buffer) abort
return g:ale#util#stdin_wrapper . ' .py '
\ . ale_linters#python#pylint#GetExecutable(a:buffer)
return ale_linters#python#pylint#GetExecutable(a:buffer)
\ . ' ' . g:ale_python_pylint_options
\ . ' --output-format text --msg-template="{path}:{line}:{column}: {msg_id} {msg}" --reports n'
\ . ' %t'
endfunction
call ale#linter#Define('python', {

View File

@ -3,6 +3,6 @@
call ale#linter#Define('sass', {
\ 'name': 'sasslint',
\ 'executable': 'sass-lint',
\ 'command': g:ale#util#stdin_wrapper . ' .sass sass-lint -v -q -f compact',
\ 'command': 'sass-lint -v -q -f compact %t',
\ 'callback': 'ale#handlers#HandleCSSLintFormat',
\})

View File

@ -1,4 +1,3 @@
" vim: set et:
" Author: Zoltan Kalmar - https://github.com/kalmiz
" Description: Basic scala support using scalac
@ -21,8 +20,10 @@ function! ale_linters#scala#scalac#Handle(buffer, lines) abort
let l:text = l:match[3]
let l:type = l:match[2] ==# 'error' ? 'E' : 'W'
let l:col = 0
if l:ln + 1 < len(a:lines)
let l:col = stridx(a:lines[l:ln + 1], '^')
if l:col == -1
let l:col = 0
endif
@ -47,6 +48,6 @@ call ale#linter#Define('scala', {
\ 'name': 'scalac',
\ 'executable': 'scalac',
\ 'output_stream': 'stderr',
\ 'command': g:ale#util#stdin_wrapper . ' .scala scalac -Ystop-after:parser',
\ 'command': 'scalac -Ystop-after:parser %t',
\ 'callback': 'ale_linters#scala#scalac#Handle',
\})

View File

@ -3,6 +3,6 @@
call ale#linter#Define('scss', {
\ 'name': 'sasslint',
\ 'executable': 'sass-lint',
\ 'command': g:ale#util#stdin_wrapper . ' .scss sass-lint -v -q -f compact',
\ 'command': 'sass-lint -v -q -f compact %t',
\ 'callback': 'ale#handlers#HandleCSSLintFormat',
\})

View File

@ -4,6 +4,14 @@
let g:ale_tex_lacheck_executable =
\ get(g:, 'ale_tex_lacheck_executable', 'lacheck')
function! ale_linters#tex#lacheck#GetExecutable(buffer) abort
return g:ale_tex_lacheck_executable
endfunction
function! ale_linters#tex#lacheck#GetCommand(buffer) abort
return g:ale_tex_lacheck_executable . ' %t'
endfunction
function! ale_linters#tex#lacheck#Handle(buffer, lines) abort
" Mattes lines like:
"
@ -43,8 +51,7 @@ endfunction
call ale#linter#Define('tex', {
\ 'name': 'lacheck',
\ 'executable': 'lacheck',
\ 'command': g:ale#util#stdin_wrapper . ' .tex '
\ . g:ale_tex_lacheck_executable,
\ 'executable_callback': 'ale_linters#tex#lacheck#GetExecutable',
\ 'command_callback': 'ale_linters#tex#lacheck#GetCommand',
\ 'callback': 'ale_linters#tex#lacheck#Handle'
\})

View File

@ -4,6 +4,6 @@
call ale#linter#Define('tex', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': g:ale#util#stdin_wrapper . ' .tex proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('text', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'command': g:ale#util#stdin_wrapper . ' .txt proselint',
\ 'command': 'proselint %t',
\})

View File

@ -38,13 +38,11 @@ function! ale_linters#typescript#tslint#Handle(buffer, lines) abort
return l:output
endfunction
function! ale_linters#typescript#tslint#BuildLintCommand(buffer_n) abort
let l:tsconfig_path = ale#util#FindNearestFile(a:buffer_n, 'tslint.json')
function! ale_linters#typescript#tslint#BuildLintCommand(buffer) abort
let l:tsconfig_path = ale#util#FindNearestFile(a:buffer, 'tslint.json')
let l:tslint_options = empty(l:tsconfig_path) ? '' : '-c ' . l:tsconfig_path
let l:ext = '.' . fnamemodify(bufname(a:buffer_n), ':e')
return g:ale#util#stdin_wrapper . ' ' . l:ext . ' tslint ' . l:tslint_options
return 'tslint ' . l:tslint_options . ' %t'
endfunction
call ale#linter#Define('typescript', {

View File

@ -40,6 +40,6 @@ call ale#linter#Define('verilog', {
\ 'name': 'iverilog',
\ 'output_stream': 'stderr',
\ 'executable': 'iverilog',
\ 'command': g:ale#util#stdin_wrapper . ' .v iverilog -t null -Wall',
\ 'command': 'iverilog -t null -Wall %t',
\ 'callback': 'ale_linters#verilog#iverilog#Handle',
\})

View File

@ -1,6 +1,16 @@
" Author: Masahiro H https://github.com/mshr-h
" Description: verilator for verilog files
function! ale_linters#verilog#verilator#GetCommand(buffer) abort
let l:filename = 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 writefile(getbufline(a:buffer, 1, '$'), l:filename)
return 'verilator --lint-only -Wall -Wno-DECLFILENAME ' . fnameescape(l:filename)
endfunction
function! ale_linters#verilog#verilator#Handle(buffer, lines) abort
" Look for lines like the following.
"
@ -25,16 +35,16 @@ function! ale_linters#verilog#verilator#Handle(buffer, lines) abort
let l:text = l:match[4]
let l:file = l:match[2]
if(l:file =~# '_verilator_linted.v')
call add(l:output, {
\ 'bufnr': a:buffer,
\ 'lnum': l:line,
\ 'vcol': 0,
\ 'col': 1,
\ 'text': l:text,
\ 'type': l:type,
\ 'nr': -1,
\})
if l:file =~# '_verilator_linted.v'
call add(l:output, {
\ 'bufnr': a:buffer,
\ 'lnum': l:line,
\ 'vcol': 0,
\ 'col': 1,
\ 'text': l:text,
\ 'type': l:type,
\ 'nr': -1,
\})
endif
endfor
@ -45,6 +55,7 @@ call ale#linter#Define('verilog', {
\ 'name': 'verilator',
\ 'output_stream': 'stderr',
\ 'executable': 'verilator',
\ 'command': g:ale#util#stdin_wrapper . ' _verilator_linted.v verilator --lint-only -Wall -Wno-DECLFILENAME',
\ 'command_callback': 'ale_linters#verilog#verilator#GetCommand',
\ 'callback': 'ale_linters#verilog#verilator#Handle',
\ 'read_buffer': 0,
\})

View File

@ -12,11 +12,11 @@ let s:format = '-f "{file_path}:{line_number}:{column_number}: {severity}: {desc
call ale#linter#Define('vim', {
\ 'name': 'vint',
\ 'executable': 'vint',
\ 'command': g:ale#util#stdin_wrapper
\ . ' .vim vint '
\ 'command': 'vint '
\ . s:warning_flag
\ . ' --no-color '
\ . s:enable_neovim
\ . s:format,
\ . s:format
\ . ' %t',
\ 'callback': 'ale#handlers#HandleGCCFormat',
\})

View File

@ -37,6 +37,6 @@ endfunction
call ale#linter#Define('yaml', {
\ 'name': 'yamllint',
\ 'executable': 'yamllint',
\ 'command': g:ale#util#stdin_wrapper . ' .yml yamllint -f parsable',
\ 'command': 'yamllint -f parsable %t',
\ 'callback': 'ale_linters#yaml#yamllint#Handle',
\})

View File

@ -1,23 +1,6 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Contains miscellaneous functions
function! s:FindWrapperScript() abort
for l:parent in split(&runtimepath, ',')
" Expand the path to deal with ~ issues.
let l:path = expand(l:parent . '/' . 'stdin-wrapper')
if filereadable(l:path)
if has('win32')
return l:path . '.exe'
endif
return l:path
endif
endfor
endfunction
let g:ale#util#stdin_wrapper = s:FindWrapperScript()
" A null file for sending output to nothing.
let g:ale#util#nul_file = '/dev/null'

View File

@ -1,21 +0,0 @@
#!/usr/bin/env bash
# Authors: w0rp <devw0rp@gmail.com>, hauleth <lukasz@niemier.pl>
# Description: This script implements a wrapper for any program which does not accept
# stdin input on most Unix machines. The input to the script is read to a
# temporary file, and the first argument sets a particular file extension
# for the temporary file.
set -eu
# All of the following arguments are read as command to run.
file_extension="$1"
shift
temp_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'ale_linter')
temp_file="$temp_dir/file$file_extension"
trap 'rm -r "$temp_dir"' EXIT
cat > "$temp_file"
"$@" "$temp_file"

Binary file not shown.

View File

@ -1,84 +0,0 @@
// Author: w0rp <devw0rp@gmail.com>
// Description: This file provides a D program for implementing
// the stdin-wrapper on Windows.
import std.algorithm;
import std.array;
import std.file;
import std.process;
import std.stdio;
import std.path;
@safe
auto createTemporaryFilename(string fileExtension) {
import std.uuid;
string filename;
do {
const randomPart = randomUUID().toString.replace("-", "_");
filename = buildPath(tempDir(), "ale_" ~ randomPart ~ fileExtension);
} while (exists(filename));
return filename;
}
@trusted
void readStdinToFile(ref File tempFile) {
stdin.byChunk(4096).copy(tempFile.lockingTextWriter());
}
// Expand program names like "csslint" to "csslint.cmd"
// D is not able to perform this kind of expanstion in spawnProcess
@safe
string expandedProgramName(string name) {
auto extArray = environment["PATHEXT"].split(";");
foreach(pathDir; environment["PATH"].split(";")) {
foreach(extension; extArray) {
const candidate = buildPath(pathDir, name ~ extension);
if (exists(candidate)) {
return candidate;
}
}
}
// We were given a full path for a program name, so use that.
if (exists(name)) {
return name;
}
return "";
}
@trusted
int runLinterProgram(string[] args) {
const expandedName = expandedProgramName(args[0]);
writeln(expandedName);
if (expandedName) {
return wait(spawnProcess([expandedName] ~ args[1..$]));
}
return 1;
}
@safe
int main(string[] args) {
const filename = createTemporaryFilename(args[1]);
auto tempFile = File(filename, "w");
scope(exit) {
tempFile.close();
remove(filename);
}
readStdinToFile(tempFile);
tempFile.close();
return runLinterProgram(args[2..$] ~ [filename]);
}

View File

@ -1,4 +0,0 @@
Execute(We should be able to find the stdin-wrapper script):
silent! cd /testplugin/test
AssertEqual expand('%:p:h:h') . '/stdin-wrapper', ale#util#stdin_wrapper