diff --git a/ale_linters/css/stylelint.vim b/ale_linters/css/stylelint.vim index 5cb67a8..9f68319 100644 --- a/ale_linters/css/stylelint.vim +++ b/ale_linters/css/stylelint.vim @@ -1,24 +1,13 @@ " Author: diartyz -let g:ale_css_stylelint_executable = -\ get(g:, 'ale_css_stylelint_executable', 'stylelint') - -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) +call ale#Set('css_stylelint_executable', 'stylelint') +call ale#Set('css_stylelint_options', '') +call ale#Set('css_stylelint_use_global', 0) function! ale_linters#css#stylelint#GetExecutable(buffer) abort - if ale#Var(a:buffer, 'css_stylelint_use_global') - return ale#Var(a:buffer, 'css_stylelint_executable') - endif - - return ale#path#ResolveLocalPath( - \ a:buffer, + return ale#node#FindExecutable(a:buffer, 'css_stylelint', [ \ 'node_modules/.bin/stylelint', - \ ale#Var(a:buffer, 'css_stylelint_executable') - \) + \]) endfunction function! ale_linters#css#stylelint#GetCommand(buffer) abort diff --git a/ale_linters/handlebars/embertemplatelint.vim b/ale_linters/handlebars/embertemplatelint.vim index 91dda70..bbf7dd9 100644 --- a/ale_linters/handlebars/embertemplatelint.vim +++ b/ale_linters/handlebars/embertemplatelint.vim @@ -1,22 +1,13 @@ " Author: Adrian Zalewski " Description: Ember-template-lint for checking Handlebars files -let g:ale_handlebars_embertemplatelint_executable = -\ get(g:, 'ale_handlebars_embertemplatelint_executable', 'ember-template-lint') - -let g:ale_handlebars_embertemplatelint_use_global = -\ get(g:, 'ale_handlebars_embertemplatelint_use_global', 0) +call ale#Set('handlebars_embertemplatelint_executable', 'ember-template-lint') +call ale#Set('handlebars_embertemplatelint_use_global', 0) function! ale_linters#handlebars#embertemplatelint#GetExecutable(buffer) abort - if ale#Var(a:buffer, 'handlebars_embertemplatelint_use_global') - return ale#Var(a:buffer, 'handlebars_embertemplatelint_executable') - endif - - return ale#path#ResolveLocalPath( - \ a:buffer, + return ale#node#FindExecutable(a:buffer, 'handlebars_embertemplatelint', [ \ 'node_modules/.bin/ember-template-lint', - \ ale#Var(a:buffer, 'handlebars_embertemplatelint_executable') - \) + \]) endfunction function! ale_linters#handlebars#embertemplatelint#GetCommand(buffer) abort diff --git a/ale_linters/html/htmlhint.vim b/ale_linters/html/htmlhint.vim index ab1c6e0..e142d22 100644 --- a/ale_linters/html/htmlhint.vim +++ b/ale_linters/html/htmlhint.vim @@ -1,21 +1,14 @@ " Author: KabbAmine , deathmaz <00maz1987@gmail.com>, diartyz " Description: HTMLHint for checking html files -" CLI options -let g:ale_html_htmlhint_options = get(g:, 'ale_html_htmlhint_options', '--format=unix') -let g:ale_html_htmlhint_executable = get(g:, 'ale_html_htmlhint_executable', 'htmlhint') -let g:ale_html_htmlhint_use_global = get(g:, 'ale_html_htmlhint_use_global', 0) +call ale#Set('html_htmlhint_options', '--format=unix') +call ale#Set('html_htmlhint_executable', 'htmlhint') +call ale#Set('html_htmlhint_use_global', 0) function! ale_linters#html#htmlhint#GetExecutable(buffer) abort - if ale#Var(a:buffer, 'html_htmlhint_use_global') - return ale#Var(a:buffer, 'html_htmlhint_executable') - endif - - return ale#path#ResolveLocalPath( - \ a:buffer, + return ale#node#FindExecutable(a:buffer, 'html_htmlhint', [ \ 'node_modules/.bin/htmlhint', - \ ale#Var(a:buffer, 'html_htmlhint_executable') - \) + \]) endfunction function! ale_linters#html#htmlhint#GetCommand(buffer) abort diff --git a/ale_linters/javascript/flow.vim b/ale_linters/javascript/flow.vim index 461dd86..4e1494e 100644 --- a/ale_linters/javascript/flow.vim +++ b/ale_linters/javascript/flow.vim @@ -1,22 +1,13 @@ " Author: Zach Perrault -- @zperrault " Description: FlowType checking for JavaScript files -let g:ale_javascript_flow_executable = -\ get(g:, 'ale_javascript_flow_executable', 'flow') - -let g:ale_javascript_flow_use_global = -\ get(g:, 'ale_javascript_flow_use_global', 0) +call ale#Set('javascript_flow_executable', 'flow') +call ale#Set('javascript_flow_use_global', 0) function! ale_linters#javascript#flow#GetExecutable(buffer) abort - if ale#Var(a:buffer, 'javascript_flow_use_global') - return ale#Var(a:buffer, 'javascript_flow_executable') - endif - - return ale#path#ResolveLocalPath( - \ a:buffer, + return ale#node#FindExecutable(a:buffer, 'javascript_flow', [ \ 'node_modules/.bin/flow', - \ ale#Var(a:buffer, 'javascript_flow_executable') - \) + \]) endfunction function! ale_linters#javascript#flow#GetCommand(buffer) abort diff --git a/ale_linters/javascript/jshint.vim b/ale_linters/javascript/jshint.vim index 757d209..93b16a8 100644 --- a/ale_linters/javascript/jshint.vim +++ b/ale_linters/javascript/jshint.vim @@ -1,22 +1,13 @@ " Author: Chris Kyrouac - https://github.com/fijshion " Description: JSHint for Javascript files -let g:ale_javascript_jshint_executable = -\ get(g:, 'ale_javascript_jshint_executable', 'jshint') - -let g:ale_javascript_jshint_use_global = -\ get(g:, 'ale_javascript_jshint_use_global', 0) +call ale#Set('javascript_jshint_executable', 'jshint') +call ale#Set('javascript_jshint_use_global', 0) function! ale_linters#javascript#jshint#GetExecutable(buffer) abort - if ale#Var(a:buffer, 'javascript_jshint_use_global') - return ale#Var(a:buffer, 'javascript_jshint_executable') - endif - - return ale#path#ResolveLocalPath( - \ a:buffer, + return ale#node#FindExecutable(a:buffer, 'javascript_jshint', [ \ 'node_modules/.bin/jshint', - \ ale#Var(a:buffer, 'javascript_jshint_executable') - \) + \]) endfunction function! ale_linters#javascript#jshint#GetCommand(buffer) abort diff --git a/ale_linters/javascript/standard.vim b/ale_linters/javascript/standard.vim index befb85f..ab5ef5a 100644 --- a/ale_linters/javascript/standard.vim +++ b/ale_linters/javascript/standard.vim @@ -1,25 +1,14 @@ " 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) +call ale#Set('javascript_standard_executable', 'standard') +call ale#Set('javascript_standard_use_global', 0) +call ale#Set('javascript_standard_options', '') function! ale_linters#javascript#standard#GetExecutable(buffer) abort - if ale#Var(a:buffer, 'javascript_standard_use_global') - return ale#Var(a:buffer, 'javascript_standard_executable') - endif - - return ale#path#ResolveLocalPath( - \ a:buffer, + return ale#node#FindExecutable(a:buffer, 'javascript_standard', [ \ 'node_modules/.bin/standard', - \ ale#Var(a:buffer, 'javascript_standard_executable') - \) + \]) endfunction function! ale_linters#javascript#standard#GetCommand(buffer) abort diff --git a/ale_linters/javascript/xo.vim b/ale_linters/javascript/xo.vim index 0c6d91a..648e0d1 100644 --- a/ale_linters/javascript/xo.vim +++ b/ale_linters/javascript/xo.vim @@ -1,25 +1,14 @@ " Author: Daniel Lupu " Description: xo for JavaScript files -let g:ale_javascript_xo_executable = -\ get(g:, 'ale_javascript_xo_executable', 'xo') - -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) +call ale#Set('javascript_xo_executable', 'xo') +call ale#Set('javascript_xo_use_global', 0) +call ale#Set('javascript_xo_options', '') function! ale_linters#javascript#xo#GetExecutable(buffer) abort - if ale#Var(a:buffer, 'javascript_xo_use_global') - return ale#Var(a:buffer, 'javascript_xo_executable') - endif - - return ale#path#ResolveLocalPath( - \ a:buffer, + return ale#node#FindExecutable(a:buffer, 'javascript_xo', [ \ 'node_modules/.bin/xo', - \ ale#Var(a:buffer, 'javascript_xo_executable') - \) + \]) endfunction function! ale_linters#javascript#xo#GetCommand(buffer) abort diff --git a/ale_linters/sass/stylelint.vim b/ale_linters/sass/stylelint.vim index 14d5467..98c3725 100644 --- a/ale_linters/sass/stylelint.vim +++ b/ale_linters/sass/stylelint.vim @@ -1,21 +1,12 @@ " Author: diartyz -let g:ale_sass_stylelint_executable = -\ get(g:, 'ale_sass_stylelint_executable', 'stylelint') - -let g:ale_sass_stylelint_use_global = -\ get(g:, 'ale_sass_stylelint_use_global', 0) +call ale#Set('sass_stylelint_executable', 'stylelint') +call ale#Set('sass_stylelint_use_global', 0) function! ale_linters#sass#stylelint#GetExecutable(buffer) abort - if ale#Var(a:buffer, 'sass_stylelint_use_global') - return ale#Var(a:buffer, 'sass_stylelint_executable') - endif - - return ale#path#ResolveLocalPath( - \ a:buffer, + return ale#node#FindExecutable(a:buffer, 'sass_stylelint', [ \ 'node_modules/.bin/stylelint', - \ ale#Var(a:buffer, 'sass_stylelint_executable') - \) + \]) endfunction function! ale_linters#sass#stylelint#GetCommand(buffer) abort diff --git a/ale_linters/scss/stylelint.vim b/ale_linters/scss/stylelint.vim index af46268..00189a8 100644 --- a/ale_linters/scss/stylelint.vim +++ b/ale_linters/scss/stylelint.vim @@ -1,21 +1,12 @@ " Author: diartyz -let g:ale_scss_stylelint_executable = -\ get(g:, 'ale_scss_stylelint_executable', 'stylelint') - -let g:ale_scss_stylelint_use_global = -\ get(g:, 'ale_scss_stylelint_use_global', 0) +call ale#Set('scss_stylelint_executable', 'stylelint') +call ale#Set('scss_stylelint_use_global', 0) function! ale_linters#scss#stylelint#GetExecutable(buffer) abort - if ale#Var(a:buffer, 'scss_stylelint_use_global') - return ale#Var(a:buffer, 'scss_stylelint_executable') - endif - - return ale#path#ResolveLocalPath( - \ a:buffer, + return ale#node#FindExecutable(a:buffer, 'scss_stylelint', [ \ 'node_modules/.bin/stylelint', - \ ale#Var(a:buffer, 'scss_stylelint_executable') - \) + \]) endfunction function! ale_linters#scss#stylelint#GetCommand(buffer) abort diff --git a/ale_linters/typescript/tslint.vim b/ale_linters/typescript/tslint.vim index c382ed2..4478445 100644 --- a/ale_linters/typescript/tslint.vim +++ b/ale_linters/typescript/tslint.vim @@ -1,25 +1,14 @@ " Author: Prashanth Chandra https://github.com/prashcr " Description: tslint for TypeScript files -let g:ale_typescript_tslint_executable = -\ get(g:, 'ale_typescript_tslint_executable', 'tslint') - -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) +call ale#Set('typescript_tslint_executable', 'tslint') +call ale#Set('typescript_tslint_config_path', '') +call ale#Set('typescript_tslint_use_global', 0) function! ale_linters#typescript#tslint#GetExecutable(buffer) abort - if ale#Var(a:buffer, 'typescript_tslint_use_global') - return ale#Var(a:buffer, 'typescript_tslint_executable') - endif - - return ale#path#ResolveLocalPath( - \ a:buffer, + return ale#node#FindExecutable(a:buffer, 'typescript_tslint', [ \ 'node_modules/.bin/tslint', - \ ale#Var(a:buffer, 'typescript_tslint_executable') - \) + \]) endfunction function! ale_linters#typescript#tslint#Handle(buffer, lines) abort diff --git a/autoload/ale/handlers/eslint.vim b/autoload/ale/handlers/eslint.vim index 1785211..080005a 100644 --- a/autoload/ale/handlers/eslint.vim +++ b/autoload/ale/handlers/eslint.vim @@ -5,25 +5,11 @@ call ale#Set('javascript_eslint_executable', 'eslint') call ale#Set('javascript_eslint_use_global', 0) function! ale#handlers#eslint#GetExecutable(buffer) abort - if ale#Var(a:buffer, 'javascript_eslint_use_global') - 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 [ + return ale#node#FindExecutable(a:buffer, 'javascript_eslint', [ \ 'node_modules/.bin/eslint_d', \ 'node_modules/eslint/bin/eslint.js', \ '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 function! s:FindConfig(buffer) abort diff --git a/autoload/ale/node.vim b/autoload/ale/node.vim new file mode 100644 index 0000000..54b53fb --- /dev/null +++ b/autoload/ale/node.vim @@ -0,0 +1,22 @@ +" Author: w0rp +" 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