Make code more consistent

This commit is contained in:
w0rp 2017-04-15 12:52:08 +01:00
parent c9a5d9845b
commit cab68cba25
13 changed files with 184 additions and 183 deletions

View File

@ -1,38 +1,37 @@
" Author: Lucas Kolstad <lkolstad@uw.edu> " Author: Lucas Kolstad <lkolstad@uw.edu>
" Description: gcc linter for asm files " Description: gcc linter for asm files
let g:ale_asm_gcc_options = let g:ale_asm_gcc_options = get(g:, 'ale_asm_gcc_options', '-Wall')
\ get(g:, 'ale_asm_gcc_options', '-Wall')
function! ale_linters#asm#gcc#GetCommand(buffer) abort function! ale_linters#asm#gcc#GetCommand(buffer) abort
return 'gcc -x assembler -fsyntax-only ' return 'gcc -x assembler -fsyntax-only '
\ . '-iquote ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h')) \ . '-iquote ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h'))
\ . ' ' . g:ale_asm_gcc_options . ' -' \ . ' ' . g:ale_asm_gcc_options . ' -'
endfunction endfunction
function! ale_linters#asm#gcc#Handle(buffer, lines) abort function! ale_linters#asm#gcc#Handle(buffer, lines) abort
let l:pattern = '^.\+:\(\d\+\): \([^:]\+\): \(.\+\)$' let l:pattern = '^.\+:\(\d\+\): \([^:]\+\): \(.\+\)$'
let l:output = [] let l:output = []
for l:line in a:lines for l:line in a:lines
let l:match = matchlist(l:line, l:pattern) let l:match = matchlist(l:line, l:pattern)
if len(l:match) == 0 if len(l:match) == 0
continue continue
endif endif
call add(l:output, { call add(l:output, {
\ 'bufnr': a:buffer, \ 'bufnr': a:buffer,
\ 'lnum': l:match[1] + 0, \ 'lnum': l:match[1] + 0,
\ 'vcol': 0, \ 'vcol': 0,
\ 'col': 0, \ 'col': 0,
\ 'text': l:match[3], \ 'text': l:match[3],
\ 'type': l:match[2] =~? 'error' ? 'E' : 'W', \ 'type': l:match[2] =~? 'error' ? 'E' : 'W',
\ 'nr': -1, \ 'nr': -1,
\}) \})
endfor endfor
return l:output return l:output
endfunction endfunction
call ale#linter#Define('asm', { call ale#linter#Define('asm', {

View File

@ -35,10 +35,10 @@ function! ale_linters#chef#foodcritic#Handle(buffer, lines) abort
endfunction endfunction
function! ale_linters#chef#foodcritic#GetCommand(buffer) abort function! ale_linters#chef#foodcritic#GetCommand(buffer) abort
return printf('%s %s %%t', return printf('%s %s %%t',
\ g:ale_chef_foodcritic_executable, \ g:ale_chef_foodcritic_executable,
\ escape(g:ale_chef_foodcritic_options, '~') \ escape(g:ale_chef_foodcritic_options, '~')
\) \)
endfunction endfunction
@ -48,4 +48,3 @@ call ale#linter#Define('chef', {
\ 'command_callback': 'ale_linters#chef#foodcritic#GetCommand', \ 'command_callback': 'ale_linters#chef#foodcritic#GetCommand',
\ 'callback': 'ale_linters#chef#foodcritic#Handle', \ 'callback': 'ale_linters#chef#foodcritic#Handle',
\}) \})

View File

@ -3,15 +3,15 @@
" Set this option to change the GCC options for warnings for C. " Set this option to change the GCC options for warnings for C.
if !exists('g:ale_cpp_gcc_options') if !exists('g:ale_cpp_gcc_options')
" added c++14 standard support " added c++14 standard support
" POSIX thread and standard c++ thread and atomic library Linker " POSIX thread and standard c++ thread and atomic library Linker
" let g:ale_cpp_gcc_options = '-std=c++1z' for c++17 " let g:ale_cpp_gcc_options = '-std=c++1z' for c++17
" for previous version and default, you can just use " for previous version and default, you can just use
" let g:ale_cpp_gcc_options = '-Wall' " let g:ale_cpp_gcc_options = '-Wall'
" for more see man pages of gcc " for more see man pages of gcc
" $ man g++ " $ man g++
" make sure g++ in your $PATH " make sure g++ in your $PATH
" Add flags according to your requirements " Add flags according to your requirements
let g:ale_cpp_gcc_options = '-std=c++14 -Wall' let g:ale_cpp_gcc_options = '-std=c++14 -Wall'
endif endif

View File

@ -24,11 +24,11 @@ function! ale_linters#crystal#crystal#Handle(buffer, lines) abort
endfunction endfunction
function! ale_linters#crystal#crystal#GetCommand(buffer) abort function! ale_linters#crystal#crystal#GetCommand(buffer) abort
let l:crystal_cmd = 'crystal build -f json --no-codegen -o ' let l:crystal_cmd = 'crystal build -f json --no-codegen -o '
let l:crystal_cmd .= shellescape(g:ale#util#nul_file) let l:crystal_cmd .= shellescape(g:ale#util#nul_file)
let l:crystal_cmd .= ' %t' let l:crystal_cmd .= ' %t'
return l:crystal_cmd return l:crystal_cmd
endfunction endfunction
call ale#linter#Define('crystal', { call ale#linter#Define('crystal', {

View File

@ -1,43 +1,44 @@
" Author: hauleth - https://github.com/hauleth " Author: hauleth - https://github.com/hauleth
function! ale_linters#dockerfile#hadolint#Handle(buffer, lines) abort function! ale_linters#dockerfile#hadolint#Handle(buffer, lines) abort
" Matches patterns line the following: " Matches patterns line the following:
" "
" stdin:19: F: Pipe chain should start with a raw value. " stdin:19: F: Pipe chain should start with a raw value.
let l:pattern = '\v^/dev/stdin:?(\d+)? (\S+) (.+)$' let l:pattern = '\v^/dev/stdin:?(\d+)? (\S+) (.+)$'
let l:output = [] let l:output = []
for l:line in a:lines for l:line in a:lines
let l:match = matchlist(l:line, l:pattern) let l:match = matchlist(l:line, l:pattern)
if len(l:match) == 0 if len(l:match) == 0
continue continue
endif endif
let l:lnum = 0 let l:lnum = 0
if l:match[1] !=# '' if l:match[1] !=# ''
let l:lnum = l:match[1] + 0 let l:lnum = l:match[1] + 0
endif endif
let l:type = 'W' let l:type = 'W'
let l:text = l:match[3] let l:text = l:match[3]
call add(l:output, { call add(l:output, {
\ 'bufnr': a:buffer, \ 'bufnr': a:buffer,
\ 'lnum': l:lnum, \ 'lnum': l:lnum,
\ 'col': 0, \ 'col': 0,
\ 'type': l:type, \ 'type': l:type,
\ 'text': l:text, \ 'text': l:text,
\ 'nr': l:match[2], \ 'nr': l:match[2],
\}) \})
endfor endfor
return l:output return l:output
endfunction endfunction
call ale#linter#Define('dockerfile', { call ale#linter#Define('dockerfile', {
\ 'name': 'hadolint', \ 'name': 'hadolint',
\ 'executable': 'hadolint', \ 'executable': 'hadolint',
\ 'command': 'hadolint -', \ 'command': 'hadolint -',
\ 'callback': 'ale_linters#dockerfile#hadolint#Handle' }) \ 'callback': 'ale_linters#dockerfile#hadolint#Handle',
\})

View File

@ -1,42 +1,43 @@
" Author: hauleth - https://github.com/hauleth " Author: hauleth - https://github.com/hauleth
function! ale_linters#elixir#credo#Handle(buffer, lines) abort function! ale_linters#elixir#credo#Handle(buffer, lines) abort
" Matches patterns line the following: " Matches patterns line the following:
" "
" lib/filename.ex:19:7: F: Pipe chain should start with a raw value. " lib/filename.ex:19:7: F: Pipe chain should start with a raw value.
let l:pattern = '\v:(\d+):?(\d+)?: (.): (.+)$' let l:pattern = '\v:(\d+):?(\d+)?: (.): (.+)$'
let l:output = [] let l:output = []
for l:line in a:lines for l:line in a:lines
let l:match = matchlist(l:line, l:pattern) let l:match = matchlist(l:line, l:pattern)
if len(l:match) == 0 if len(l:match) == 0
continue continue
endif endif
let l:type = l:match[3] let l:type = l:match[3]
let l:text = l:match[4] let l:text = l:match[4]
if l:type ==# 'C' if l:type ==# 'C'
let l:type = 'E' let l:type = 'E'
elseif l:type ==# 'R' elseif l:type ==# 'R'
let l:type = 'W' let l:type = 'W'
endif endif
call add(l:output, { call add(l:output, {
\ 'bufnr': a:buffer, \ 'bufnr': a:buffer,
\ 'lnum': l:match[1] + 0, \ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0, \ 'col': l:match[2] + 0,
\ 'type': l:type, \ 'type': l:type,
\ 'text': l:text, \ 'text': l:text,
\}) \})
endfor endfor
return l:output return l:output
endfunction endfunction
call ale#linter#Define('elixir', { call ale#linter#Define('elixir', {
\ 'name': 'credo', \ 'name': 'credo',
\ 'executable': 'mix', \ 'executable': 'mix',
\ 'command': 'mix credo suggest --format=flycheck --read-from-stdin %s', \ 'command': 'mix credo suggest --format=flycheck --read-from-stdin %s',
\ 'callback': 'ale_linters#elixir#credo#Handle' }) \ 'callback': 'ale_linters#elixir#credo#Handle',
\})

View File

@ -4,22 +4,25 @@
" inspired by work from dzhou121 <dzhou121@gmail.com> " inspired by work from dzhou121 <dzhou121@gmail.com>
function! ale_linters#go#gobuild#GoEnv(buffer) abort function! ale_linters#go#gobuild#GoEnv(buffer) abort
if exists('s:go_env') if exists('s:go_env')
return '' return ''
endif endif
return 'go env GOPATH GOROOT' return 'go env GOPATH GOROOT'
endfunction endfunction
function! ale_linters#go#gobuild#GetCommand(buffer, goenv_output) abort function! ale_linters#go#gobuild#GetCommand(buffer, goenv_output) abort
if !exists('s:go_env') if !exists('s:go_env')
let s:go_env = { let s:go_env = {
\ 'GOPATH': a:goenv_output[0], \ 'GOPATH': a:goenv_output[0],
\ 'GOROOT': a:goenv_output[1], \ 'GOROOT': a:goenv_output[1],
\} \}
endif endif
" Run go test in local directory with relative path
return 'GOPATH=' . s:go_env.GOPATH . ' cd ' . fnamemodify(bufname(a:buffer), ':.:h') . ' && go test -c -o /dev/null ./' " Run go test in local directory with relative path
return 'GOPATH=' . s:go_env.GOPATH
\ . ' cd ' . fnamemodify(bufname(a:buffer), ':.:h')
\ . ' && go test -c -o /dev/null ./'
endfunction endfunction
function! ale_linters#go#gobuild#Handler(buffer, lines) abort function! ale_linters#go#gobuild#Handler(buffer, lines) abort
@ -42,7 +45,7 @@ function! ale_linters#go#gobuild#HandleGoBuildErrors(buffer, full_filename, line
for l:line in a:lines for l:line in a:lines
let l:match = matchlist(l:line, l:pattern) let l:match = matchlist(l:line, l:pattern)
" Omit errors from imported go packages " Omit errors from imported go packages
if len(l:match) == 0 || l:line !~ l:filename if len(l:match) == 0 || l:line !~ l:filename
continue continue
endif endif

View File

@ -27,7 +27,7 @@ endfunction
function! ale_linters#handlebars#embertemplatelint#Handle(buffer, lines) abort function! ale_linters#handlebars#embertemplatelint#Handle(buffer, lines) abort
if len(a:lines) == 0 if len(a:lines) == 0
return [] return []
end endif
let l:output = [] let l:output = []

View File

@ -51,7 +51,7 @@ function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort
endfunction endfunction
function! ale_linters#nim#nimcheck#GetCommand(buffer) function! ale_linters#nim#nimcheck#GetCommand(buffer) abort
return 'nim check --path:' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h')) . ' --threads:on --verbosity:0 --colors:off --listFullPaths %t' return 'nim check --path:' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h')) . ' --threads:on --verbosity:0 --colors:off --listFullPaths %t'
endfunction endfunction

View File

@ -2,12 +2,11 @@
" Description: Report errors in OCaml code with Merlin " Description: Report errors in OCaml code with Merlin
if !exists('g:merlin') if !exists('g:merlin')
finish finish
endif endif
function! ale_linters#ocaml#merlin#Handle(buffer, lines) abort function! ale_linters#ocaml#merlin#Handle(buffer, lines) abort
let l:errors = merlin#ErrorLocList() return merlin#ErrorLocList()
return l:errors
endfunction endfunction
call ale#linter#Define('ocaml', { call ale#linter#Define('ocaml', {
@ -16,4 +15,3 @@ call ale#linter#Define('ocaml', {
\ 'command': 'true', \ 'command': 'true',
\ 'callback': 'ale_linters#ocaml#merlin#Handle', \ 'callback': 'ale_linters#ocaml#merlin#Handle',
\}) \})

View File

@ -32,9 +32,9 @@ function! ale_linters#ruby#rubocop#Handle(buffer, lines) abort
endfunction endfunction
function! ale_linters#ruby#rubocop#GetCommand(buffer) abort function! ale_linters#ruby#rubocop#GetCommand(buffer) abort
return 'rubocop --format emacs --force-exclusion ' . return 'rubocop --format emacs --force-exclusion '
\ g:ale_ruby_rubocop_options . \ . g:ale_ruby_rubocop_options
\ ' --stdin ' . bufname(a:buffer) \ . ' --stdin ' . bufname(a:buffer)
endfunction endfunction
" Set this option to change Rubocop options. " Set this option to change Rubocop options.

View File

@ -8,49 +8,49 @@ let g:ale_tex_chktex_options =
\ get(g:, 'ale_tex_chktex_options', '-I') \ get(g:, 'ale_tex_chktex_options', '-I')
function! ale_linters#tex#chktex#GetCommand(buffer) abort function! ale_linters#tex#chktex#GetCommand(buffer) abort
" Check for optional .chktexrc " Check for optional .chktexrc
let l:chktex_config = ale#util#FindNearestFile( let l:chktex_config = ale#util#FindNearestFile(
\ a:buffer, \ a:buffer,
\ '.chktexrc') \ '.chktexrc')
let l:command = g:ale_tex_chktex_executable let l:command = g:ale_tex_chktex_executable
" Avoid bug when used without -p (last warning has gibberish for a filename) " Avoid bug when used without -p (last warning has gibberish for a filename)
let l:command .= ' -v0 -p stdin -q' let l:command .= ' -v0 -p stdin -q'
if !empty(l:chktex_config) if !empty(l:chktex_config)
let l:command .= ' -l ' . fnameescape(l:chktex_config) let l:command .= ' -l ' . fnameescape(l:chktex_config)
endif endif
let l:command .= ' ' . g:ale_tex_chktex_options let l:command .= ' ' . g:ale_tex_chktex_options
return l:command return l:command
endfunction endfunction
function! ale_linters#tex#chktex#Handle(buffer, lines) abort function! ale_linters#tex#chktex#Handle(buffer, lines) abort
" Mattes lines like: " Mattes lines like:
" "
" stdin:499:2:24:Delete this space to maintain correct pagereferences. " stdin:499:2:24:Delete this space to maintain correct pagereferences.
" stdin:507:81:3:You should enclose the previous parenthesis with `{}'. " stdin:507:81:3:You should enclose the previous parenthesis with `{}'.
let l:pattern = '^stdin:\(\d\+\):\(\d\+\):\(\d\+\):\(.\+\)$' let l:pattern = '^stdin:\(\d\+\):\(\d\+\):\(\d\+\):\(.\+\)$'
let l:output = [] let l:output = []
for l:line in a:lines for l:line in a:lines
let l:match = matchlist(l:line, l:pattern) let l:match = matchlist(l:line, l:pattern)
if len(l:match) == 0 if len(l:match) == 0
continue continue
endif endif
call add(l:output, { call add(l:output, {
\ 'bufnr': a:buffer, \ 'bufnr': a:buffer,
\ 'lnum': l:match[1] + 0, \ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0, \ 'col': l:match[2] + 0,
\ 'text': l:match[4] . ' (' . (l:match[3]+0) . ')', \ 'text': l:match[4] . ' (' . (l:match[3]+0) . ')',
\ 'type': 'W', \ 'type': 'W',
\}) \})
endfor endfor
return l:output return l:output
endfunction endfunction
call ale#linter#Define('tex', { call ale#linter#Define('tex', {

View File

@ -13,38 +13,38 @@ function! ale_linters#tex#lacheck#GetCommand(buffer) abort
endfunction endfunction
function! ale_linters#tex#lacheck#Handle(buffer, lines) abort function! ale_linters#tex#lacheck#Handle(buffer, lines) abort
" Mattes lines like: " Mattes lines like:
" "
" "book.tex", line 37: possible unwanted space at "{" " "book.tex", line 37: possible unwanted space at "{"
" "book.tex", line 38: missing `\ ' after "etc." " "book.tex", line 38: missing `\ ' after "etc."
let l:pattern = '^".\+", line \(\d\+\): \(.\+\)$' let l:pattern = '^".\+", line \(\d\+\): \(.\+\)$'
let l:output = [] let l:output = []
for l:line in a:lines for l:line in a:lines
let l:match = matchlist(l:line, l:pattern) let l:match = matchlist(l:line, l:pattern)
if len(l:match) == 0 if len(l:match) == 0
continue continue
endif endif
" lacheck follows `\input{}` commands. If the cwd is not the same as the " lacheck follows `\input{}` commands. If the cwd is not the same as the
" file in the buffer then it will fail to find the inputed items. We do not " file in the buffer then it will fail to find the inputed items. We do not
" want warnings from those items anyway " want warnings from those items anyway
if !empty(matchstr(l:match[2], '^Could not open ".\+"$')) if !empty(matchstr(l:match[2], '^Could not open ".\+"$'))
continue continue
endif endif
call add(l:output, { call add(l:output, {
\ 'bufnr': a:buffer, \ 'bufnr': a:buffer,
\ 'lnum': l:match[1] + 0, \ 'lnum': l:match[1] + 0,
\ 'col': 0, \ 'col': 0,
\ 'text': l:match[2], \ 'text': l:match[2],
\ 'type': 'W', \ 'type': 'W',
\}) \})
endfor endfor
return l:output return l:output
endfunction endfunction
call ale#linter#Define('tex', { call ale#linter#Define('tex', {