Refactor running of local Node programs with a helper function
This commit is contained in:
		
							parent
							
								
									b934dc52b6
								
							
						
					
					
						commit
						c4f22186bd
					
				@ -1,24 +1,13 @@
 | 
			
		||||
" Author: diartyz <diartyz@gmail.com>
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
@ -1,22 +1,13 @@
 | 
			
		||||
" Author: Adrian Zalewski <aazalewski@hotmail.com>
 | 
			
		||||
" 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
 | 
			
		||||
 | 
			
		||||
@ -1,21 +1,14 @@
 | 
			
		||||
" Author: KabbAmine <amine.kabb@gmail.com>, deathmaz <00maz1987@gmail.com>, diartyz <diartyz@gmail.com>
 | 
			
		||||
" 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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -1,25 +1,14 @@
 | 
			
		||||
" Author: Daniel Lupu <lupu.daniel.f@gmail.com>
 | 
			
		||||
" 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
 | 
			
		||||
 | 
			
		||||
@ -1,21 +1,12 @@
 | 
			
		||||
" Author: diartyz <diartyz@gmail.com>
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
@ -1,21 +1,12 @@
 | 
			
		||||
" Author: diartyz <diartyz@gmail.com>
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										22
									
								
								autoload/ale/node.vim
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								autoload/ale/node.vim
									
									
									
									
									
										Normal 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
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user