2017-02-05 17:26:26 +00:00
|
|
|
" Author: Ahmed El Gabri <@ahmedelgabri>
|
|
|
|
" Description: standardjs for JavaScript files
|
|
|
|
|
|
|
|
let g:ale_javascript_standard_executable =
|
|
|
|
\ get(g:, 'ale_javascript_standard_executable', 'standard')
|
|
|
|
|
|
|
|
let g:ale_javascript_standard_options =
|
|
|
|
\ get(g:, 'ale_javascript_standard_options', '')
|
|
|
|
|
|
|
|
let g:ale_javascript_standard_use_global =
|
|
|
|
\ get(g:, 'ale_javascript_standard_use_global', 0)
|
|
|
|
|
|
|
|
function! ale_linters#javascript#standard#GetExecutable(buffer) abort
|
2017-04-16 00:24:08 +00:00
|
|
|
if ale#Var(a:buffer, 'javascript_standard_use_global')
|
|
|
|
return ale#Var(a:buffer, 'javascript_standard_executable')
|
2017-02-05 17:26:26 +00:00
|
|
|
endif
|
|
|
|
|
2017-04-17 22:29:02 +00:00
|
|
|
return ale#path#ResolveLocalPath(
|
2017-02-05 17:26:26 +00:00
|
|
|
\ a:buffer,
|
|
|
|
\ 'node_modules/.bin/standard',
|
2017-04-16 00:24:08 +00:00
|
|
|
\ ale#Var(a:buffer, 'javascript_standard_executable')
|
2017-02-05 17:26:26 +00:00
|
|
|
\)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#javascript#standard#GetCommand(buffer) abort
|
|
|
|
return ale_linters#javascript#standard#GetExecutable(a:buffer)
|
2017-04-16 00:24:08 +00:00
|
|
|
\ . ' ' . ale#Var(a:buffer, 'javascript_standard_options')
|
2017-02-05 17:26:26 +00:00
|
|
|
\ . ' --stdin %s'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#javascript#standard#Handle(buffer, lines) abort
|
|
|
|
" Matches patterns line the following:
|
|
|
|
"
|
|
|
|
" /path/to/some-filename.js:47:14: Strings must use singlequote.
|
|
|
|
" /path/to/some-filename.js:56:41: Expected indentation of 2 spaces but found 4.
|
|
|
|
" /path/to/some-filename.js:13:3: Parsing error: Unexpected token
|
|
|
|
let l:pattern = '^.*:\(\d\+\):\(\d\+\): \(.\+\)$'
|
|
|
|
let l:output = []
|
|
|
|
|
2017-04-17 23:35:53 +00:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2017-02-05 17:26:26 +00:00
|
|
|
let l:type = 'Error'
|
|
|
|
let l:text = l:match[3]
|
|
|
|
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'bufnr': a:buffer,
|
|
|
|
\ 'lnum': l:match[1] + 0,
|
|
|
|
\ 'col': l:match[2] + 0,
|
|
|
|
\ 'text': l:text,
|
|
|
|
\ 'type': 'E',
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('javascript', {
|
|
|
|
\ 'name': 'standard',
|
|
|
|
\ 'executable_callback': 'ale_linters#javascript#standard#GetExecutable',
|
|
|
|
\ 'command_callback': 'ale_linters#javascript#standard#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#javascript#standard#Handle',
|
|
|
|
\})
|
|
|
|
|