Refactor running of local Node programs with a helper function

This commit is contained in:
w0rp 2017-05-27 17:11:03 +01:00
parent b934dc52b6
commit c4f22186bd
12 changed files with 69 additions and 157 deletions

View File

@ -1,24 +1,13 @@
" Author: diartyz <diartyz@gmail.com> " Author: diartyz <diartyz@gmail.com>
let g:ale_css_stylelint_executable = call ale#Set('css_stylelint_executable', 'stylelint')
\ get(g:, 'ale_css_stylelint_executable', 'stylelint') call ale#Set('css_stylelint_options', '')
call ale#Set('css_stylelint_use_global', 0)
let g:ale_css_stylelint_options =
\ get(g:, 'ale_css_stylelint_options', '')
let g:ale_css_stylelint_use_global =
\ get(g:, 'ale_css_stylelint_use_global', 0)
function! ale_linters#css#stylelint#GetExecutable(buffer) abort function! ale_linters#css#stylelint#GetExecutable(buffer) abort
if ale#Var(a:buffer, 'css_stylelint_use_global') return ale#node#FindExecutable(a:buffer, 'css_stylelint', [
return ale#Var(a:buffer, 'css_stylelint_executable')
endif
return ale#path#ResolveLocalPath(
\ a:buffer,
\ 'node_modules/.bin/stylelint', \ 'node_modules/.bin/stylelint',
\ ale#Var(a:buffer, 'css_stylelint_executable') \])
\)
endfunction endfunction
function! ale_linters#css#stylelint#GetCommand(buffer) abort function! ale_linters#css#stylelint#GetCommand(buffer) abort

View File

@ -1,22 +1,13 @@
" Author: Adrian Zalewski <aazalewski@hotmail.com> " Author: Adrian Zalewski <aazalewski@hotmail.com>
" Description: Ember-template-lint for checking Handlebars files " Description: Ember-template-lint for checking Handlebars files
let g:ale_handlebars_embertemplatelint_executable = call ale#Set('handlebars_embertemplatelint_executable', 'ember-template-lint')
\ get(g:, 'ale_handlebars_embertemplatelint_executable', 'ember-template-lint') call ale#Set('handlebars_embertemplatelint_use_global', 0)
let g:ale_handlebars_embertemplatelint_use_global =
\ get(g:, 'ale_handlebars_embertemplatelint_use_global', 0)
function! ale_linters#handlebars#embertemplatelint#GetExecutable(buffer) abort function! ale_linters#handlebars#embertemplatelint#GetExecutable(buffer) abort
if ale#Var(a:buffer, 'handlebars_embertemplatelint_use_global') return ale#node#FindExecutable(a:buffer, 'handlebars_embertemplatelint', [
return ale#Var(a:buffer, 'handlebars_embertemplatelint_executable')
endif
return ale#path#ResolveLocalPath(
\ a:buffer,
\ 'node_modules/.bin/ember-template-lint', \ 'node_modules/.bin/ember-template-lint',
\ ale#Var(a:buffer, 'handlebars_embertemplatelint_executable') \])
\)
endfunction endfunction
function! ale_linters#handlebars#embertemplatelint#GetCommand(buffer) abort function! ale_linters#handlebars#embertemplatelint#GetCommand(buffer) abort

View File

@ -1,21 +1,14 @@
" Author: KabbAmine <amine.kabb@gmail.com>, deathmaz <00maz1987@gmail.com>, diartyz <diartyz@gmail.com> " Author: KabbAmine <amine.kabb@gmail.com>, deathmaz <00maz1987@gmail.com>, diartyz <diartyz@gmail.com>
" Description: HTMLHint for checking html files " Description: HTMLHint for checking html files
" CLI options call ale#Set('html_htmlhint_options', '--format=unix')
let g:ale_html_htmlhint_options = get(g:, 'ale_html_htmlhint_options', '--format=unix') call ale#Set('html_htmlhint_executable', 'htmlhint')
let g:ale_html_htmlhint_executable = get(g:, 'ale_html_htmlhint_executable', 'htmlhint') call ale#Set('html_htmlhint_use_global', 0)
let g:ale_html_htmlhint_use_global = get(g:, 'ale_html_htmlhint_use_global', 0)
function! ale_linters#html#htmlhint#GetExecutable(buffer) abort function! ale_linters#html#htmlhint#GetExecutable(buffer) abort
if ale#Var(a:buffer, 'html_htmlhint_use_global') return ale#node#FindExecutable(a:buffer, 'html_htmlhint', [
return ale#Var(a:buffer, 'html_htmlhint_executable')
endif
return ale#path#ResolveLocalPath(
\ a:buffer,
\ 'node_modules/.bin/htmlhint', \ 'node_modules/.bin/htmlhint',
\ ale#Var(a:buffer, 'html_htmlhint_executable') \])
\)
endfunction endfunction
function! ale_linters#html#htmlhint#GetCommand(buffer) abort function! ale_linters#html#htmlhint#GetCommand(buffer) abort

View File

@ -1,22 +1,13 @@
" Author: Zach Perrault -- @zperrault " Author: Zach Perrault -- @zperrault
" Description: FlowType checking for JavaScript files " Description: FlowType checking for JavaScript files
let g:ale_javascript_flow_executable = call ale#Set('javascript_flow_executable', 'flow')
\ get(g:, 'ale_javascript_flow_executable', 'flow') call ale#Set('javascript_flow_use_global', 0)
let g:ale_javascript_flow_use_global =
\ get(g:, 'ale_javascript_flow_use_global', 0)
function! ale_linters#javascript#flow#GetExecutable(buffer) abort function! ale_linters#javascript#flow#GetExecutable(buffer) abort
if ale#Var(a:buffer, 'javascript_flow_use_global') return ale#node#FindExecutable(a:buffer, 'javascript_flow', [
return ale#Var(a:buffer, 'javascript_flow_executable')
endif
return ale#path#ResolveLocalPath(
\ a:buffer,
\ 'node_modules/.bin/flow', \ 'node_modules/.bin/flow',
\ ale#Var(a:buffer, 'javascript_flow_executable') \])
\)
endfunction endfunction
function! ale_linters#javascript#flow#GetCommand(buffer) abort function! ale_linters#javascript#flow#GetCommand(buffer) abort

View File

@ -1,22 +1,13 @@
" Author: Chris Kyrouac - https://github.com/fijshion " Author: Chris Kyrouac - https://github.com/fijshion
" Description: JSHint for Javascript files " Description: JSHint for Javascript files
let g:ale_javascript_jshint_executable = call ale#Set('javascript_jshint_executable', 'jshint')
\ get(g:, 'ale_javascript_jshint_executable', 'jshint') call ale#Set('javascript_jshint_use_global', 0)
let g:ale_javascript_jshint_use_global =
\ get(g:, 'ale_javascript_jshint_use_global', 0)
function! ale_linters#javascript#jshint#GetExecutable(buffer) abort function! ale_linters#javascript#jshint#GetExecutable(buffer) abort
if ale#Var(a:buffer, 'javascript_jshint_use_global') return ale#node#FindExecutable(a:buffer, 'javascript_jshint', [
return ale#Var(a:buffer, 'javascript_jshint_executable')
endif
return ale#path#ResolveLocalPath(
\ a:buffer,
\ 'node_modules/.bin/jshint', \ 'node_modules/.bin/jshint',
\ ale#Var(a:buffer, 'javascript_jshint_executable') \])
\)
endfunction endfunction
function! ale_linters#javascript#jshint#GetCommand(buffer) abort function! ale_linters#javascript#jshint#GetCommand(buffer) abort

View File

@ -1,25 +1,14 @@
" Author: Ahmed El Gabri <@ahmedelgabri> " Author: Ahmed El Gabri <@ahmedelgabri>
" Description: standardjs for JavaScript files " Description: standardjs for JavaScript files
let g:ale_javascript_standard_executable = call ale#Set('javascript_standard_executable', 'standard')
\ get(g:, 'ale_javascript_standard_executable', 'standard') call ale#Set('javascript_standard_use_global', 0)
call ale#Set('javascript_standard_options', '')
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 function! ale_linters#javascript#standard#GetExecutable(buffer) abort
if ale#Var(a:buffer, 'javascript_standard_use_global') return ale#node#FindExecutable(a:buffer, 'javascript_standard', [
return ale#Var(a:buffer, 'javascript_standard_executable')
endif
return ale#path#ResolveLocalPath(
\ a:buffer,
\ 'node_modules/.bin/standard', \ 'node_modules/.bin/standard',
\ ale#Var(a:buffer, 'javascript_standard_executable') \])
\)
endfunction endfunction
function! ale_linters#javascript#standard#GetCommand(buffer) abort function! ale_linters#javascript#standard#GetCommand(buffer) abort

View File

@ -1,25 +1,14 @@
" Author: Daniel Lupu <lupu.daniel.f@gmail.com> " Author: Daniel Lupu <lupu.daniel.f@gmail.com>
" Description: xo for JavaScript files " Description: xo for JavaScript files
let g:ale_javascript_xo_executable = call ale#Set('javascript_xo_executable', 'xo')
\ get(g:, 'ale_javascript_xo_executable', 'xo') call ale#Set('javascript_xo_use_global', 0)
call ale#Set('javascript_xo_options', '')
let g:ale_javascript_xo_options =
\ get(g:, 'ale_javascript_xo_options', '')
let g:ale_javascript_xo_use_global =
\ get(g:, 'ale_javascript_xo_use_global', 0)
function! ale_linters#javascript#xo#GetExecutable(buffer) abort function! ale_linters#javascript#xo#GetExecutable(buffer) abort
if ale#Var(a:buffer, 'javascript_xo_use_global') return ale#node#FindExecutable(a:buffer, 'javascript_xo', [
return ale#Var(a:buffer, 'javascript_xo_executable')
endif
return ale#path#ResolveLocalPath(
\ a:buffer,
\ 'node_modules/.bin/xo', \ 'node_modules/.bin/xo',
\ ale#Var(a:buffer, 'javascript_xo_executable') \])
\)
endfunction endfunction
function! ale_linters#javascript#xo#GetCommand(buffer) abort function! ale_linters#javascript#xo#GetCommand(buffer) abort

View File

@ -1,21 +1,12 @@
" Author: diartyz <diartyz@gmail.com> " Author: diartyz <diartyz@gmail.com>
let g:ale_sass_stylelint_executable = call ale#Set('sass_stylelint_executable', 'stylelint')
\ get(g:, 'ale_sass_stylelint_executable', 'stylelint') call ale#Set('sass_stylelint_use_global', 0)
let g:ale_sass_stylelint_use_global =
\ get(g:, 'ale_sass_stylelint_use_global', 0)
function! ale_linters#sass#stylelint#GetExecutable(buffer) abort function! ale_linters#sass#stylelint#GetExecutable(buffer) abort
if ale#Var(a:buffer, 'sass_stylelint_use_global') return ale#node#FindExecutable(a:buffer, 'sass_stylelint', [
return ale#Var(a:buffer, 'sass_stylelint_executable')
endif
return ale#path#ResolveLocalPath(
\ a:buffer,
\ 'node_modules/.bin/stylelint', \ 'node_modules/.bin/stylelint',
\ ale#Var(a:buffer, 'sass_stylelint_executable') \])
\)
endfunction endfunction
function! ale_linters#sass#stylelint#GetCommand(buffer) abort function! ale_linters#sass#stylelint#GetCommand(buffer) abort

View File

@ -1,21 +1,12 @@
" Author: diartyz <diartyz@gmail.com> " Author: diartyz <diartyz@gmail.com>
let g:ale_scss_stylelint_executable = call ale#Set('scss_stylelint_executable', 'stylelint')
\ get(g:, 'ale_scss_stylelint_executable', 'stylelint') call ale#Set('scss_stylelint_use_global', 0)
let g:ale_scss_stylelint_use_global =
\ get(g:, 'ale_scss_stylelint_use_global', 0)
function! ale_linters#scss#stylelint#GetExecutable(buffer) abort function! ale_linters#scss#stylelint#GetExecutable(buffer) abort
if ale#Var(a:buffer, 'scss_stylelint_use_global') return ale#node#FindExecutable(a:buffer, 'scss_stylelint', [
return ale#Var(a:buffer, 'scss_stylelint_executable')
endif
return ale#path#ResolveLocalPath(
\ a:buffer,
\ 'node_modules/.bin/stylelint', \ 'node_modules/.bin/stylelint',
\ ale#Var(a:buffer, 'scss_stylelint_executable') \])
\)
endfunction endfunction
function! ale_linters#scss#stylelint#GetCommand(buffer) abort function! ale_linters#scss#stylelint#GetCommand(buffer) abort

View File

@ -1,25 +1,14 @@
" Author: Prashanth Chandra https://github.com/prashcr " Author: Prashanth Chandra https://github.com/prashcr
" Description: tslint for TypeScript files " Description: tslint for TypeScript files
let g:ale_typescript_tslint_executable = call ale#Set('typescript_tslint_executable', 'tslint')
\ get(g:, 'ale_typescript_tslint_executable', 'tslint') call ale#Set('typescript_tslint_config_path', '')
call ale#Set('typescript_tslint_use_global', 0)
let g:ale_typescript_tslint_config_path =
\ get(g:, 'ale_typescript_tslint_config_path', '')
let g:ale_typescript_tslint_use_global =
\ get(g:, 'ale_typescript_tslint_use_global', 0)
function! ale_linters#typescript#tslint#GetExecutable(buffer) abort function! ale_linters#typescript#tslint#GetExecutable(buffer) abort
if ale#Var(a:buffer, 'typescript_tslint_use_global') return ale#node#FindExecutable(a:buffer, 'typescript_tslint', [
return ale#Var(a:buffer, 'typescript_tslint_executable')
endif
return ale#path#ResolveLocalPath(
\ a:buffer,
\ 'node_modules/.bin/tslint', \ 'node_modules/.bin/tslint',
\ ale#Var(a:buffer, 'typescript_tslint_executable') \])
\)
endfunction endfunction
function! ale_linters#typescript#tslint#Handle(buffer, lines) abort function! ale_linters#typescript#tslint#Handle(buffer, lines) abort

View File

@ -5,25 +5,11 @@ call ale#Set('javascript_eslint_executable', 'eslint')
call ale#Set('javascript_eslint_use_global', 0) call ale#Set('javascript_eslint_use_global', 0)
function! ale#handlers#eslint#GetExecutable(buffer) abort function! ale#handlers#eslint#GetExecutable(buffer) abort
if ale#Var(a:buffer, 'javascript_eslint_use_global') return ale#node#FindExecutable(a:buffer, 'javascript_eslint', [
return ale#Var(a:buffer, 'javascript_eslint_executable')
endif
" Look for eslint_d first, then the path React uses, then the basic
" eslint path.
for l:path in [
\ 'node_modules/.bin/eslint_d', \ 'node_modules/.bin/eslint_d',
\ 'node_modules/eslint/bin/eslint.js', \ 'node_modules/eslint/bin/eslint.js',
\ 'node_modules/.bin/eslint', \ 'node_modules/.bin/eslint',
\] \])
let l:executable = ale#path#FindNearestFile(a:buffer, l:path)
if !empty(l:executable)
return l:executable
endif
endfor
return ale#Var(a:buffer, 'javascript_eslint_executable')
endfunction endfunction
function! s:FindConfig(buffer) abort function! s:FindConfig(buffer) abort

22
autoload/ale/node.vim Normal file
View File

@ -0,0 +1,22 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Functions for working with Node executables.
" Given a buffer number, a base variable name, and a list of paths to search
" for in ancestor directories, detect the executable path for a Node program.
"
" The use_global and executable options for the relevant program will be used.
function! ale#node#FindExecutable(buffer, base_var_name, path_list) abort
if ale#Var(a:buffer, a:base_var_name . '_use_global')
return ale#Var(a:buffer, a:base_var_name . '_executable')
endif
for l:path in a:path_list
let l:executable = ale#path#FindNearestFile(a:buffer, l:path)
if !empty(l:executable)
return l:executable
endif
endfor
return ale#Var(a:buffer, a:base_var_name . '_executable')
endfunction