mirror of https://github.com/amix/vimrc.git
parent
5a2572df03
commit
fae0b73f0d
@ -0,0 +1,54 @@ |
||||
" Author: Raphael Hoegger - https://github.com/pfuender |
||||
" Description: Cookstyle (RuboCop based), a code style analyzer for Ruby files |
||||
|
||||
call ale#Set('chef_cookstyle_executable', 'cookstyle') |
||||
call ale#Set('chef_cookstyle_options', '') |
||||
|
||||
function! ale_linters#chef#cookstyle#GetCommand(buffer) abort |
||||
let l:options = ale#Var(a:buffer, 'chef_cookstyle_options') |
||||
|
||||
return '%e' . ale#Pad(escape(l:options, '~')) . ' --force-exclusion --format json --stdin ' . ' %s' |
||||
endfunction |
||||
|
||||
function! ale_linters#chef#cookstyle#Handle(buffer, lines) abort |
||||
if len(a:lines) == 0 |
||||
return [] |
||||
endif |
||||
|
||||
let l:errors = ale#util#FuzzyJSONDecode(a:lines[0], {}) |
||||
|
||||
if !has_key(l:errors, 'summary') |
||||
\|| l:errors['summary']['offense_count'] == 0 |
||||
\|| empty(l:errors['files']) |
||||
return [] |
||||
endif |
||||
|
||||
let l:output = [] |
||||
|
||||
for l:error in l:errors['files'][0]['offenses'] |
||||
let l:start_col = str2nr(l:error['location']['start_column']) |
||||
let l:end_col = str2nr(l:error['location']['last_column']) |
||||
|
||||
if !l:end_col |
||||
let l:end_col = l:start_col + 1 |
||||
endif |
||||
|
||||
call add(l:output, { |
||||
\ 'lnum': str2nr(l:error['location']['line']), |
||||
\ 'col': l:start_col, |
||||
\ 'end_col': l:end_col, |
||||
\ 'code': l:error['cop_name'], |
||||
\ 'text': l:error['message'], |
||||
\ 'type': l:error['severity'] is? 'convention' ? 'W' : 'E', |
||||
\}) |
||||
endfor |
||||
|
||||
return l:output |
||||
endfunction |
||||
|
||||
call ale#linter#Define('chef', { |
||||
\ 'name': 'cookstyle', |
||||
\ 'executable': {b -> ale#Var(b, 'chef_cookstyle_executable')}, |
||||
\ 'command': function('ale_linters#chef#cookstyle#GetCommand'), |
||||
\ 'callback': 'ale_linters#chef#cookstyle#Handle', |
||||
\}) |
@ -0,0 +1,34 @@ |
||||
" Author: Masashi Iizuka <liquidz.uo@gmail.com> |
||||
" Description: linter for clojure using clj-kondo https://github.com/borkdude/clj-kondo |
||||
|
||||
function! ale_linters#clojure#clj_kondo#HandleCljKondoFormat(buffer, lines) abort |
||||
" output format |
||||
" <filename>:<line>:<column>: <issue type>: <message> |
||||
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+):? ((Exception|error|warning): ?(.+))$' |
||||
let l:output = [] |
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern) |
||||
let l:type = 'E' |
||||
|
||||
if l:match[4] is? 'warning' |
||||
let l:type = 'W' |
||||
endif |
||||
|
||||
call add(l:output, { |
||||
\ 'lnum': l:match[1] + 0, |
||||
\ 'col': l:match[2] + 0, |
||||
\ 'text': l:match[3], |
||||
\ 'type': l:type, |
||||
\}) |
||||
endfor |
||||
|
||||
return l:output |
||||
endfunction |
||||
|
||||
call ale#linter#Define('clojure', { |
||||
\ 'name': 'clj-kondo', |
||||
\ 'output_stream': 'stdout', |
||||
\ 'executable': 'clj-kondo', |
||||
\ 'command': 'clj-kondo --lint %t', |
||||
\ 'callback': 'ale_linters#clojure#clj_kondo#HandleCljKondoFormat', |
||||
\}) |
@ -0,0 +1,9 @@ |
||||
" Author: harttle <yangjvn@126.com> |
||||
" Description: fecs for CSS files |
||||
|
||||
call ale#linter#Define('css', { |
||||
\ 'name': 'fecs', |
||||
\ 'executable': function('ale#handlers#fecs#GetExecutable'), |
||||
\ 'command': function('ale#handlers#fecs#GetCommand'), |
||||
\ 'callback': 'ale#handlers#fecs#Handle', |
||||
\}) |
@ -0,0 +1,30 @@ |
||||
" Author: w0rp <devw0rp@gmail.com> |
||||
" Author: Jerko Steiner <https://github.com/jeremija> |
||||
" Description: https://github.com/saibing/gopls |
||||
|
||||
call ale#Set('go_gopls_executable', 'gopls') |
||||
call ale#Set('go_gopls_options', '--mode stdio') |
||||
|
||||
function! ale_linters#go#gopls#GetCommand(buffer) abort |
||||
return '%e' . ale#Pad(ale#Var(a:buffer, 'go_gopls_options')) |
||||
endfunction |
||||
|
||||
function! ale_linters#go#gopls#FindProjectRoot(buffer) abort |
||||
let l:project_root = ale#path#FindNearestFile(a:buffer, 'go.mod') |
||||
let l:mods = ':h' |
||||
|
||||
if empty(l:project_root) |
||||
let l:project_root = ale#path#FindNearestDirectory(a:buffer, '.git') |
||||
let l:mods = ':h:h' |
||||
endif |
||||
|
||||
return !empty(l:project_root) ? fnamemodify(l:project_root, l:mods) : '' |
||||
endfunction |
||||
|
||||
call ale#linter#Define('go', { |
||||
\ 'name': 'gopls', |
||||
\ 'lsp': 'stdio', |
||||
\ 'executable': {b -> ale#Var(b, 'go_gopls_executable')}, |
||||
\ 'command': function('ale_linters#go#gopls#GetCommand'), |
||||
\ 'project_root': function('ale_linters#go#gopls#FindProjectRoot'), |
||||
\}) |
@ -0,0 +1,9 @@ |
||||
" Author: harttle <yangjvn@126.com> |
||||
" Description: fecs for HTMl files |
||||
|
||||
call ale#linter#Define('html', { |
||||
\ 'name': 'fecs', |
||||
\ 'executable': function('ale#handlers#fecs#GetExecutable'), |
||||
\ 'command': function('ale#handlers#fecs#GetCommand'), |
||||
\ 'callback': 'ale#handlers#fecs#Handle', |
||||
\}) |
@ -0,0 +1,137 @@ |
||||
" Author: Horacio Sanson <https://github.com/hsanson> |
||||
" Description: Support for the Eclipse language server https://github.com/eclipse/eclipse.jdt.ls |
||||
|
||||
let s:version_cache = {} |
||||
|
||||
call ale#Set('java_eclipselsp_path', ale#path#Simplify($HOME . '/eclipse.jdt.ls')) |
||||
call ale#Set('java_eclipselsp_executable', 'java') |
||||
|
||||
function! ale_linters#java#eclipselsp#Executable(buffer) abort |
||||
return ale#Var(a:buffer, 'java_eclipselsp_executable') |
||||
endfunction |
||||
|
||||
function! ale_linters#java#eclipselsp#TargetPath(buffer) abort |
||||
return ale#Var(a:buffer, 'java_eclipselsp_path') |
||||
endfunction |
||||
|
||||
function! ale_linters#java#eclipselsp#JarPath(buffer) abort |
||||
let l:path = ale_linters#java#eclipselsp#TargetPath(a:buffer) |
||||
|
||||
" Search jar file within repository path when manually built using mvn |
||||
let l:repo_path = l:path . '/org.eclipse.jdt.ls.product/target/repository' |
||||
let l:files = globpath(l:repo_path, '**/plugins/org.eclipse.equinox.launcher_\d\.\d\.\d\d\d\.*\.jar', 1, 1) |
||||
|
||||
if len(l:files) == 1 |
||||
return l:files[0] |
||||
endif |
||||
|
||||
" Search jar file within VSCode extensions folder. |
||||
let l:files = globpath(l:path, '**/plugins/org.eclipse.equinox.launcher_\d\.\d\.\d\d\d\.*\.jar', 1, 1) |
||||
|
||||
if len(l:files) == 1 |
||||
return l:files[0] |
||||
endif |
||||
|
||||
return '' |
||||
endfunction |
||||
|
||||
function! ale_linters#java#eclipselsp#ConfigurationPath(buffer) abort |
||||
let l:path = fnamemodify(ale_linters#java#eclipselsp#JarPath(a:buffer), ':p:h:h') |
||||
|
||||
if has('win32') |
||||
let l:path = l:path . '/config_win' |
||||
elseif has('macunix') |
||||
let l:path = l:path . '/config_mac' |
||||
else |
||||
let l:path = l:path . '/config_linux' |
||||
endif |
||||
|
||||
return ale#path#Simplify(l:path) |
||||
endfunction |
||||
|
||||
function! ale_linters#java#eclipselsp#VersionCheck(version_lines) abort |
||||
return s:GetVersion('', a:version_lines) |
||||
endfunction |
||||
|
||||
function! s:GetVersion(executable, version_lines) abort |
||||
let l:version = [] |
||||
|
||||
for l:line in a:version_lines |
||||
let l:match = matchlist(l:line, '\(\d\+\)\.\(\d\+\)\.\(\d\+\)') |
||||
|
||||
if !empty(l:match) |
||||
let l:version = [l:match[1] + 0, l:match[2] + 0, l:match[3] + 0] |
||||
let s:version_cache[a:executable] = l:version |
||||
break |
||||
endif |
||||
endfor |
||||
|
||||
return l:version |
||||
endfunction |
||||
|
||||
function! ale_linters#java#eclipselsp#CommandWithVersion(buffer, version_lines, meta) abort |
||||
let l:executable = ale_linters#java#eclipselsp#Executable(a:buffer) |
||||
let l:version = s:GetVersion(l:executable, a:version_lines) |
||||
|
||||
return ale_linters#java#eclipselsp#Command(a:buffer, l:version) |
||||
endfunction |
||||
|
||||
function! ale_linters#java#eclipselsp#Command(buffer, version) abort |
||||
let l:path = ale#Var(a:buffer, 'java_eclipselsp_path') |
||||
|
||||
let l:executable = ale_linters#java#eclipselsp#Executable(a:buffer) |
||||
|
||||
let l:cmd = [ ale#Escape(l:executable), |
||||
\ '-Declipse.application=org.eclipse.jdt.ls.core.id1', |
||||
\ '-Dosgi.bundles.defaultStartLevel=4', |
||||
\ '-Declipse.product=org.eclipse.jdt.ls.core.product', |
||||
\ '-Dlog.level=ALL', |
||||
\ '-noverify', |
||||
\ '-Xmx1G', |
||||
\ '-jar', |
||||
\ ale_linters#java#eclipselsp#JarPath(a:buffer), |
||||
\ '-configuration', |
||||
\ ale_linters#java#eclipselsp#ConfigurationPath(a:buffer), |
||||
\ '-data', |
||||
\ ale#java#FindProjectRoot(a:buffer) |
||||
\ ] |
||||
|
||||
if ale#semver#GTE(a:version, [1, 9]) |
||||
call add(l:cmd, '--add-modules=ALL-SYSTEM') |
||||
call add(l:cmd, '--add-opens java.base/java.util=ALL-UNNAMED') |
||||
call add(l:cmd, '--add-opens java.base/java.lang=ALL-UNNAMED') |
||||
endif |
||||
|
||||
return join(l:cmd, ' ') |
||||
endfunction |
||||
|
||||
function! ale_linters#java#eclipselsp#RunWithVersionCheck(buffer) abort |
||||
let l:executable = ale_linters#java#eclipselsp#Executable(a:buffer) |
||||
|
||||
if empty(l:executable) |
||||
return '' |
||||
endif |
||||
|
||||
let l:cache = s:version_cache |
||||
|
||||
if has_key(s:version_cache, l:executable) |
||||
return ale_linters#java#eclipselsp#Command(a:buffer, s:version_cache[l:executable]) |
||||
endif |
||||
|
||||
let l:command = ale#Escape(l:executable) . ' -version' |
||||
|
||||
return ale#command#Run( |
||||
\ a:buffer, |
||||
\ l:command, |
||||
\ function('ale_linters#java#eclipselsp#CommandWithVersion') |
||||
\) |
||||
endfunction |
||||
|
||||
call ale#linter#Define('java', { |
||||
\ 'name': 'eclipselsp', |
||||
\ 'lsp': 'stdio', |
||||
\ 'executable': function('ale_linters#java#eclipselsp#Executable'), |
||||
\ 'command': function('ale_linters#java#eclipselsp#RunWithVersionCheck'), |
||||
\ 'language': 'java', |
||||
\ 'project_root': function('ale#java#FindProjectRoot'), |
||||
\}) |
@ -0,0 +1,10 @@ |
||||
" Author: harttle <yangjvn@126.com> |
||||
" Description: fecs for JavaScript files |
||||
|
||||
call ale#linter#Define('javascript', { |
||||
\ 'name': 'fecs', |
||||
\ 'executable': function('ale#handlers#fecs#GetExecutable'), |
||||
\ 'command': function('ale#handlers#fecs#GetCommand'), |
||||
\ 'read_buffer': 0, |
||||
\ 'callback': 'ale#handlers#fecs#Handle', |
||||
\}) |
@ -0,0 +1,91 @@ |
||||
" Author: Jesse Harris - https://github.com/zigford |
||||
" Description: This file adds support for powershell scripts synatax errors |
||||
|
||||
call ale#Set('powershell_powershell_executable', 'pwsh') |
||||
|
||||
function! ale_linters#powershell#powershell#GetExecutable(buffer) abort |
||||
return ale#Var(a:buffer, 'powershell_powershell_executable') |
||||
endfunction |
||||
|
||||
" Some powershell magic to show syntax errors without executing the script |
||||
" thanks to keith hill: |
||||
" https://rkeithhill.wordpress.com/2007/10/30/powershell-quicktip-preparsing-scripts-to-check-for-syntax-errors/ |
||||
function! ale_linters#powershell#powershell#GetCommand(buffer) abort |
||||
let l:script = ['Param($Script); |
||||
\ trap {$_;continue} & { |
||||
\ $Contents = Get-Content -Path $Script; |
||||
\ $Contents = [string]::Join([Environment]::NewLine, $Contents); |
||||
\ [void]$ExecutionContext.InvokeCommand.NewScriptBlock($Contents); |
||||
\ };'] |
||||
|
||||
return ale#powershell#RunPowerShell( |
||||
\ a:buffer, 'powershell_powershell', l:script) |
||||
endfunction |
||||
|
||||
" Parse powershell error output using regex into a list of dicts |
||||
function! ale_linters#powershell#powershell#Handle(buffer, lines) abort |
||||
let l:output = [] |
||||
" Our 3 patterns we need to scrape the data for the dicts |
||||
let l:patterns = [ |
||||
\ '\v^At line:(\d+) char:(\d+)', |
||||
\ '\v^(At|\+| )@!.*', |
||||
\ '\vFullyQualifiedErrorId : (\w+)', |
||||
\] |
||||
|
||||
let l:matchcount = 0 |
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:patterns) |
||||
" We want to work with 3 matches per syntax error |
||||
let l:matchcount = l:matchcount + 1 |
||||
|
||||
if l:matchcount == 1 || str2nr(l:match[1]) |
||||
" First match consists of 2 capture groups, and |
||||
" can capture the line and col |
||||
if exists('l:item') |
||||
" We may be here because the last syntax |
||||
" didn't emit a code, and so only had 2 |
||||
" matches |
||||
call add(l:output, l:item) |
||||
let l:matchcount = 1 |
||||
endif |
||||
|
||||
let l:item = { |
||||
\ 'lnum': str2nr(l:match[1]), |
||||
\ 'col': str2nr(l:match[2]), |
||||
\ 'type': 'E', |
||||
\} |
||||
elseif l:matchcount == 2 |
||||
" Second match[0] grabs the full line in order |
||||
" to handles the text |
||||
let l:item['text'] = l:match[0] |
||||
else |
||||
" Final match handles the code, however |
||||
" powershell only emits 1 code for all errors |
||||
" so, we get the final code on the last error |
||||
" and loop over the previously added items to |
||||
" append the code we now know |
||||
call add(l:output, l:item) |
||||
unlet l:item |
||||
|
||||
if len(l:match[1]) > 0 |
||||
for l:i in l:output |
||||
let l:i['code'] = l:match[1] |
||||
endfor |
||||
endif |
||||
|
||||
" Reset the matchcount so we can begin gathering |
||||
" matches for the next syntax error |
||||
let l:matchcount = 0 |
||||
endif |
||||
endfor |
||||
|
||||
return l:output |
||||
endfunction |
||||
|
||||
call ale#linter#Define('powershell', { |
||||
\ 'name': 'powershell', |
||||
\ 'executable_callback': 'ale_linters#powershell#powershell#GetExecutable', |
||||
\ 'command_callback': 'ale_linters#powershell#powershell#GetCommand', |
||||
\ 'output_stream': 'stdout', |
||||
\ 'callback': 'ale_linters#powershell#powershell#Handle', |
||||
\}) |
@ -0,0 +1,76 @@ |
||||
" Author: Jesse Harris - https://github.com/zigford |
||||
" Description: This file adds support for lintng powershell scripts |
||||
" using the PSScriptAnalyzer module. |
||||
|
||||
" let g:ale_powershell_psscriptanalyzer_exclusions = |
||||
" \ 'PSAvoidUsingWriteHost,PSAvoidGlobalVars' |
||||
call ale#Set('powershell_psscriptanalyzer_exclusions', '') |
||||
call ale#Set('powershell_psscriptanalyzer_executable', 'pwsh') |
||||
call ale#Set('powershell_psscriptanalyzer_module', |
||||
\ 'psscriptanalyzer') |
||||
|
||||
function! ale_linters#powershell#psscriptanalyzer#GetExecutable(buffer) abort |
||||
return ale#Var(a:buffer, 'powershell_psscriptanalyzer_executable') |
||||
endfunction |
||||
|
||||
" Run Invoke-ScriptAnalyzer and output each linting message as 4 seperate lines |
||||
" for each parsing |
||||
function! ale_linters#powershell#psscriptanalyzer#GetCommand(buffer) abort |
||||
let l:exclude_option = ale#Var( |
||||
\ a:buffer, 'powershell_psscriptanalyzer_exclusions') |
||||
let l:module = ale#Var( |
||||
\ a:buffer, 'powershell_psscriptanalyzer_module') |
||||
let l:script = ['Param($Script); |
||||
\ Invoke-ScriptAnalyzer "$Script" ' |
||||
\ . (!empty(l:exclude_option) ? '-Exclude ' . l:exclude_option : '') |
||||
\ . '| ForEach-Object { |
||||
\ $_.Line; |
||||
\ $_.Severity; |
||||
\ $_.Message; |
||||
\ $_.RuleName}'] |
||||
|
||||
return ale#powershell#RunPowerShell( |
||||
\ a:buffer, |
||||
\ 'powershell_psscriptanalyzer', |
||||
\ l:script) |
||||
endfunction |
||||
|
||||
" add every 4 lines to an item(Dict) and every item to a list |
||||
" return the list |
||||
function! ale_linters#powershell#psscriptanalyzer#Handle(buffer, lines) abort |
||||
let l:output = [] |
||||
let l:lcount = 0 |
||||
|
||||
for l:line in a:lines |
||||
if l:lcount is# 0 |
||||
" the very first line |
||||
let l:item = {'lnum': str2nr(l:line)} |
||||
elseif l:lcount is# 1 |
||||
if l:line is# 'Error' |
||||
let l:item['type'] = 'E' |
||||
elseif l:line is# 'Information' |
||||
let l:item['type'] = 'I' |
||||
else |
||||
let l:item['type'] = 'W' |
||||
endif |
||||
elseif l:lcount is# 2 |
||||
let l:item['text'] = l:line |
||||
elseif l:lcount is# 3 |
||||
let l:item['code'] = l:line |
||||
call add(l:output, l:item) |
||||
let l:lcount = -1 |
||||
endif |
||||
|
||||
let l:lcount = l:lcount + 1 |
||||
endfor |
||||
|
||||
return l:output |
||||
endfunction |
||||
|
||||
call ale#linter#Define('powershell', { |
||||
\ 'name': 'psscriptanalyzer', |
||||
\ 'executable': function('ale_linters#powershell#psscriptanalyzer#GetExecutable'), |
||||
\ 'command': function('ale_linters#powershell#psscriptanalyzer#GetCommand'), |
||||
\ 'output_stream': 'stdout', |
||||
\ 'callback': 'ale_linters#powershell#psscriptanalyzer#Handle', |
||||
\}) |