Add support for formatting filenames into commands, and use it to fix linting with older eslint versions.

This commit is contained in:
w0rp 2016-10-04 13:50:44 +01:00
parent 6269ffa0b2
commit 705f4232c0
2 changed files with 11 additions and 5 deletions

View File

@ -10,9 +10,9 @@ let g:loaded_ale_linters_javascript_eslint = 1
function! ale_linters#javascript#eslint#Handle(buffer, lines) function! ale_linters#javascript#eslint#Handle(buffer, lines)
" Matches patterns line the following: " Matches patterns line the following:
" "
" <text>:47:14: Missing trailing comma. [Warning/comma-dangle] " /path/to/some-filename.js:47:14: Missing trailing comma. [Warning/comma-dangle]
" <text>:56:41: Missing semicolon. [Error/semi] " /path/to/some-filename.js:56:41: Missing semicolon. [Error/semi]
let pattern = '^<text>:\(\d\+\):\(\d\+\): \(.\+\) \[\(.\+\)\]' let pattern = '^.*:\(\d\+\):\(\d\+\): \(.\+\) \[\(.\+\)\]$'
let output = [] let output = []
for line in a:lines for line in a:lines
@ -48,13 +48,13 @@ endfunction
call ALEAddLinter('javascript', { call ALEAddLinter('javascript', {
\ 'name': 'eslint', \ 'name': 'eslint',
\ 'executable': 'eslint', \ 'executable': 'eslint',
\ 'command': 'eslint -f unix --stdin', \ 'command': 'eslint -f unix --stdin --stdin-filename %s',
\ 'callback': 'ale_linters#javascript#eslint#Handle', \ 'callback': 'ale_linters#javascript#eslint#Handle',
\}) \})
call ALEAddLinter('javascript.jsx', { call ALEAddLinter('javascript.jsx', {
\ 'name': 'eslint', \ 'name': 'eslint',
\ 'executable': 'eslint', \ 'executable': 'eslint',
\ 'command': 'eslint -f unix --stdin', \ 'command': 'eslint -f unix --stdin --stdin-filename %s',
\ 'callback': 'ale_linters#javascript#eslint#Handle', \ 'callback': 'ale_linters#javascript#eslint#Handle',
\}) \})

View File

@ -154,6 +154,12 @@ function! s:ApplyLinter(buffer, linter)
let command = a:linter.command let command = a:linter.command
endif endif
if command =~# '%s'
" If there is a '%s' in the command string, replace it with the name
" of the file.
let command = printf(command, shellescape(getbufinfo(a:buffer)[0].name))
endif
if has('nvim') if has('nvim')
if a:linter.output_stream ==# 'stderr' if a:linter.output_stream ==# 'stderr'
" Read from stderr instead of stdout. " Read from stderr instead of stdout.