From 705f4232c0920a7d1e3f4b70f06fc982015a43d7 Mon Sep 17 00:00:00 2001 From: w0rp Date: Tue, 4 Oct 2016 13:50:44 +0100 Subject: [PATCH] Add support for formatting filenames into commands, and use it to fix linting with older eslint versions. --- ale_linters/javascript/eslint.vim | 10 +++++----- plugin/ale/zmain.vim | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ale_linters/javascript/eslint.vim b/ale_linters/javascript/eslint.vim index 8a4e03bf..e31a5b15 100644 --- a/ale_linters/javascript/eslint.vim +++ b/ale_linters/javascript/eslint.vim @@ -10,9 +10,9 @@ let g:loaded_ale_linters_javascript_eslint = 1 function! ale_linters#javascript#eslint#Handle(buffer, lines) " Matches patterns line the following: " - " :47:14: Missing trailing comma. [Warning/comma-dangle] - " :56:41: Missing semicolon. [Error/semi] - let pattern = '^:\(\d\+\):\(\d\+\): \(.\+\) \[\(.\+\)\]' + " /path/to/some-filename.js:47:14: Missing trailing comma. [Warning/comma-dangle] + " /path/to/some-filename.js:56:41: Missing semicolon. [Error/semi] + let pattern = '^.*:\(\d\+\):\(\d\+\): \(.\+\) \[\(.\+\)\]$' let output = [] for line in a:lines @@ -48,13 +48,13 @@ endfunction call ALEAddLinter('javascript', { \ 'name': 'eslint', \ 'executable': 'eslint', -\ 'command': 'eslint -f unix --stdin', +\ 'command': 'eslint -f unix --stdin --stdin-filename %s', \ 'callback': 'ale_linters#javascript#eslint#Handle', \}) call ALEAddLinter('javascript.jsx', { \ 'name': 'eslint', \ 'executable': 'eslint', -\ 'command': 'eslint -f unix --stdin', +\ 'command': 'eslint -f unix --stdin --stdin-filename %s', \ 'callback': 'ale_linters#javascript#eslint#Handle', \}) diff --git a/plugin/ale/zmain.vim b/plugin/ale/zmain.vim index 26085b66..3cfe28db 100644 --- a/plugin/ale/zmain.vim +++ b/plugin/ale/zmain.vim @@ -154,6 +154,12 @@ function! s:ApplyLinter(buffer, linter) let command = a:linter.command 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 a:linter.output_stream ==# 'stderr' " Read from stderr instead of stdout.