mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-28 22:02:31 +08:00
Improve ALE project style checking
* The project style linter now runs while you type. * Now the scripts for checking the project require blank lines. * Many style issues have been found and fixed.
This commit is contained in:
@@ -27,7 +27,7 @@ let s:getcmdwintype_exists = exists('*getcmdwintype')
|
||||
function! ale#ShouldDoNothing(buffer) abort
|
||||
" The checks are split into separate if statements to make it possible to
|
||||
" profile each check individually with Vim's profiling tools.
|
||||
|
||||
"
|
||||
" Do nothing if ALE is disabled.
|
||||
if !getbufvar(a:buffer, 'ale_enabled', get(g:, 'ale_enabled', 0))
|
||||
return 1
|
||||
|
||||
@@ -54,6 +54,7 @@ function! ale#c#ParseCFlags(path_prefix, cflag_line) abort
|
||||
call add(l:previous_options, l:option)
|
||||
" Check if cflag contained a '-' and should not have been splitted
|
||||
let l:option_list = split(l:option, '\zs')
|
||||
|
||||
if l:option_list[-1] isnot# ' '
|
||||
continue
|
||||
endif
|
||||
|
||||
@@ -75,6 +75,7 @@ endfunction
|
||||
" Check if we should look for completions for a language.
|
||||
function! ale#completion#GetPrefix(filetype, line, column) abort
|
||||
let l:regex = s:GetFiletypeValue(s:should_complete_map, a:filetype)
|
||||
|
||||
" The column we're using completions for is where we are inserting text,
|
||||
" like so:
|
||||
" abc
|
||||
|
||||
@@ -231,6 +231,7 @@ function! s:HandleExit(job_id, exit_code) abort
|
||||
|
||||
if l:next_chain_index < len(get(l:linter, 'command_chain', []))
|
||||
call s:InvokeChain(l:buffer, l:executable, l:linter, l:next_chain_index, l:output)
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
@@ -595,9 +596,8 @@ function! ale#engine#ProcessChain(buffer, linter, chain_index, input) abort
|
||||
\)
|
||||
endif
|
||||
|
||||
" If we have a command to run, execute that.
|
||||
if !empty(l:command)
|
||||
" We hit a command to run, so we'll execute that
|
||||
|
||||
" The chain item can override the output_stream option.
|
||||
if has_key(l:chain_item, 'output_stream')
|
||||
let l:output_stream = l:chain_item.output_stream
|
||||
|
||||
@@ -71,6 +71,7 @@ function! ale#fix#ApplyFixes(buffer, output) abort
|
||||
if l:data.lines_before != l:lines
|
||||
call remove(g:ale_fix_buffer_data, a:buffer)
|
||||
execute 'echoerr ''The file was changed before fixing finished'''
|
||||
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -17,6 +17,7 @@ function! ale#fixers#fixjson#Fix(buffer) abort
|
||||
let l:command = l:executable . ' --stdin-filename ' . l:filename
|
||||
|
||||
let l:options = ale#Var(a:buffer, 'json_fixjson_options')
|
||||
|
||||
if l:options isnot# ''
|
||||
let l:command .= ' ' . l:options
|
||||
endif
|
||||
|
||||
@@ -5,6 +5,7 @@ call ale#Set('javascript_importjs_executable', 'importjs')
|
||||
|
||||
function! ale#fixers#importjs#ProcessOutput(buffer, output) abort
|
||||
let l:result = ale#util#FuzzyJSONDecode(a:output, [])
|
||||
|
||||
return split(get(l:result, 'fileContent', ''), "\n")
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ endfunction
|
||||
|
||||
function! ale#fixers#php_cs_fixer#Fix(buffer) abort
|
||||
let l:executable = ale#fixers#php_cs_fixer#GetExecutable(a:buffer)
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(l:executable)
|
||||
\ . ' ' . ale#Var(a:buffer, 'php_cs_fixer_options')
|
||||
|
||||
@@ -18,6 +18,7 @@ function! ale#fixers#phpcbf#Fix(buffer) abort
|
||||
let l:standard_option = !empty(l:standard)
|
||||
\ ? '--standard=' . l:standard
|
||||
\ : ''
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(l:executable) . ' --stdin-path=%s ' . l:standard_option . ' -'
|
||||
\}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
if !exists('g:ale_puppet_puppetlint_executable')
|
||||
let g:ale_puppet_puppetlint_executable = 'puppet-lint'
|
||||
endif
|
||||
|
||||
if !exists('g:ale_puppet_puppetlint_options')
|
||||
let g:ale_puppet_puppetlint_options = ''
|
||||
endif
|
||||
|
||||
@@ -10,7 +10,6 @@ function! ale#fixers#rubocop#GetCommand(buffer) abort
|
||||
\ . (!empty(l:config) ? ' --config ' . ale#Escape(l:config) : '')
|
||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||
\ . ' --auto-correct %t'
|
||||
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#rubocop#Fix(buffer) abort
|
||||
|
||||
@@ -15,7 +15,6 @@ function! ale#fixers#scalafmt#GetCommand(buffer) abort
|
||||
return ale#Escape(l:executable) . l:exec_args
|
||||
\ . (empty(l:options) ? '' : ' ' . l:options)
|
||||
\ . ' %t'
|
||||
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#scalafmt#Fix(buffer) abort
|
||||
|
||||
@@ -13,5 +13,4 @@ function! ale#fixers#shfmt#Fix(buffer) abort
|
||||
\ 'command': ale#Escape(l:executable)
|
||||
\ . (empty(l:options) ? '' : ' ' . l:options)
|
||||
\}
|
||||
|
||||
endfunction
|
||||
|
||||
@@ -11,12 +11,14 @@ function! ale#fixers#xmllint#Fix(buffer) abort
|
||||
let l:command = l:executable . ' --format ' . l:filename
|
||||
|
||||
let l:indent = ale#Var(a:buffer, 'xml_xmllint_indentsize')
|
||||
|
||||
if l:indent isnot# ''
|
||||
let l:env = ale#Env('XMLLINT_INDENT', repeat(' ', l:indent))
|
||||
let l:command = l:env . l:command
|
||||
endif
|
||||
|
||||
let l:options = ale#Var(a:buffer, 'xml_xmllint_options')
|
||||
|
||||
if l:options isnot# ''
|
||||
let l:command .= ' ' . l:options
|
||||
endif
|
||||
|
||||
@@ -9,9 +9,11 @@ function! ale#handlers#gawk#HandleGawkFormat(buffer, lines) abort
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
let l:ecode = 'E'
|
||||
|
||||
if l:match[2] is? 'warning:'
|
||||
let l:ecode = 'W'
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:match[1] + 0,
|
||||
\ 'col': 0,
|
||||
|
||||
@@ -21,5 +21,6 @@ function! ale#handlers#go#Handler(buffer, lines) abort
|
||||
\ 'type': 'E',
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
function! ale#handlers#ols#GetExecutable(buffer) abort
|
||||
let l:ols_setting = ale#handlers#ols#GetLanguage(a:buffer) . '_ols'
|
||||
|
||||
return ale#node#FindExecutable(a:buffer, l:ols_setting, [
|
||||
\ 'node_modules/.bin/ocaml-language-server',
|
||||
\])
|
||||
|
||||
@@ -14,7 +14,6 @@ endfunction
|
||||
function! ale#handlers#pony#HandlePonycFormat(buffer, lines) abort
|
||||
" Look for lines like the following.
|
||||
" /home/code/pony/classes/Wombat.pony:22:30: can't lookup private fields from outside the type
|
||||
|
||||
let l:pattern = '\v^([^:]+):(\d+):(\d+)?:? (.+)$'
|
||||
let l:output = []
|
||||
|
||||
|
||||
@@ -6,15 +6,18 @@ function! ale#handlers#redpen#HandleRedpenOutput(buffer, lines) abort
|
||||
" element.
|
||||
let l:res = json_decode(join(a:lines))[0]
|
||||
let l:output = []
|
||||
|
||||
for l:err in l:res.errors
|
||||
let l:item = {
|
||||
\ 'text': l:err.message,
|
||||
\ 'type': 'W',
|
||||
\ 'code': l:err.validator,
|
||||
\}
|
||||
|
||||
if has_key(l:err, 'startPosition')
|
||||
let l:item.lnum = l:err.startPosition.lineNum
|
||||
let l:item.col = l:err.startPosition.offset + 1
|
||||
|
||||
if has_key(l:err, 'endPosition')
|
||||
let l:item.end_lnum = l:err.endPosition.lineNum
|
||||
let l:item.end_col = l:err.endPosition.offset
|
||||
@@ -28,29 +31,35 @@ function! ale#handlers#redpen#HandleRedpenOutput(buffer, lines) abort
|
||||
|
||||
" Adjust column number for multibyte string
|
||||
let l:line = getline(l:item.lnum)
|
||||
|
||||
if l:line is# ''
|
||||
let l:line = l:err.sentence
|
||||
endif
|
||||
|
||||
let l:line = split(l:line, '\zs')
|
||||
|
||||
if l:item.col >= 2
|
||||
let l:col = 0
|
||||
|
||||
for l:strlen in map(l:line[0:(l:item.col - 2)], 'strlen(v:val)')
|
||||
let l:col = l:col + l:strlen
|
||||
endfor
|
||||
|
||||
let l:item.col = l:col + 1
|
||||
endif
|
||||
|
||||
if has_key(l:item, 'end_col')
|
||||
let l:col = 0
|
||||
|
||||
for l:strlen in map(l:line[0:(l:item.end_col - 1)], 'strlen(v:val)')
|
||||
let l:col = l:col + l:strlen
|
||||
endfor
|
||||
|
||||
let l:item.end_col = l:col
|
||||
endif
|
||||
|
||||
call add(l:output, l:item)
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -13,8 +13,10 @@ function! s:HandleSyntaxError(buffer, lines) abort
|
||||
|
||||
for l:line in a:lines
|
||||
let l:match = matchlist(l:line, l:pattern)
|
||||
|
||||
if len(l:match) == 0
|
||||
let l:match = matchlist(l:line, l:column)
|
||||
|
||||
if len(l:match) != 0
|
||||
let l:output[len(l:output) - 1]['col'] = len(l:match[1])
|
||||
endif
|
||||
|
||||
@@ -11,8 +11,10 @@ function! ale#handlers#sml#GetCmFile(buffer) abort
|
||||
let l:as_list = 1
|
||||
|
||||
let l:cmfile = ''
|
||||
|
||||
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
|
||||
let l:results = glob(l:path . '/' . l:pattern, 0, l:as_list)
|
||||
|
||||
if len(l:results) > 0
|
||||
" If there is more than one CM file, we take the first one
|
||||
" See :help ale-sml-smlnj for how to configure this.
|
||||
@@ -46,6 +48,7 @@ endfunction
|
||||
function! ale#handlers#sml#GetExecutableSmlnjCm(buffer) abort
|
||||
return s:GetExecutable(a:buffer, 'smlnj-cm')
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#sml#GetExecutableSmlnjFile(buffer) abort
|
||||
return s:GetExecutable(a:buffer, 'smlnj-file')
|
||||
endfunction
|
||||
@@ -53,7 +56,6 @@ endfunction
|
||||
function! ale#handlers#sml#Handle(buffer, lines) abort
|
||||
" Try to match basic sml errors
|
||||
" TODO(jez) We can get better errorfmt strings from Syntastic
|
||||
|
||||
let l:out = []
|
||||
let l:pattern = '^.*\:\([0-9\.]\+\)\ \(\w\+\)\:\ \(.*\)'
|
||||
let l:pattern2 = '^.*\:\([0-9]\+\)\.\?\([0-9]\+\).* \(\(Warning\|Error\): .*\)'
|
||||
@@ -83,7 +85,6 @@ function! ale#handlers#sml#Handle(buffer, lines) abort
|
||||
\})
|
||||
continue
|
||||
endif
|
||||
|
||||
endfor
|
||||
|
||||
return l:out
|
||||
|
||||
@@ -23,6 +23,7 @@ function! ale#handlers#vale#Handle(buffer, lines) abort
|
||||
endif
|
||||
|
||||
let l:output = []
|
||||
|
||||
for l:error in l:errors[keys(l:errors)[0]]
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:error['Line'],
|
||||
|
||||
@@ -278,11 +278,13 @@ function! ale#job#IsRunning(job_id) abort
|
||||
try
|
||||
" In NeoVim, if the job isn't running, jobpid() will throw.
|
||||
call jobpid(a:job_id)
|
||||
|
||||
return 1
|
||||
catch
|
||||
endtry
|
||||
elseif has_key(s:job_map, a:job_id)
|
||||
let l:job = s:job_map[a:job_id].job
|
||||
|
||||
return job_status(l:job) is# 'run'
|
||||
endif
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ function! ale#list#IsQuickfixOpen() abort
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
@@ -112,9 +113,11 @@ function! s:SetListsImpl(timer_id, buffer, loclist) abort
|
||||
|
||||
" open windows vertically instead of default horizontally
|
||||
let l:open_type = ''
|
||||
|
||||
if ale#Var(a:buffer, 'list_vertical') == 1
|
||||
let l:open_type = 'vert '
|
||||
endif
|
||||
|
||||
if g:ale_set_quickfix
|
||||
if !ale#list#IsQuickfixOpen()
|
||||
silent! execute l:open_type . 'copen ' . str2nr(ale#Var(a:buffer, 'list_window_size'))
|
||||
|
||||
@@ -99,6 +99,7 @@ function! s:CreateTSServerMessageData(message) abort
|
||||
endif
|
||||
|
||||
let l:data = json_encode(l:obj) . "\n"
|
||||
|
||||
return [l:is_notification ? 0 : l:obj.seq, l:data]
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ function! ale#socket#IsOpen(channel_id) abort
|
||||
endif
|
||||
|
||||
let l:channel = s:channel_map[a:channel_id].channel
|
||||
|
||||
return ch_status(l:channel) is# 'open'
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ function! ale#toggle#ToggleBuffer(buffer) abort
|
||||
" linting locally when linting is disabled globally
|
||||
if l:enabled && !g:ale_enabled
|
||||
execute 'echom ''ALE cannot be enabled locally when disabled globally'''
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ endif
|
||||
function! ale#util#JoinNeovimOutput(job, last_line, data, mode, callback) abort
|
||||
if a:mode is# 'raw'
|
||||
call a:callback(a:job, join(a:data, "\n"))
|
||||
|
||||
return ''
|
||||
endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user