Move path functions to their own file
This commit is contained in:
parent
6c762237ce
commit
e237add9fd
@ -2,7 +2,7 @@
|
|||||||
" Description: Coffee for checking coffee files
|
" Description: Coffee for checking coffee files
|
||||||
|
|
||||||
function! ale_linters#coffee#coffee#GetExecutable(buffer) abort
|
function! ale_linters#coffee#coffee#GetExecutable(buffer) abort
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/coffee',
|
\ 'node_modules/.bin/coffee',
|
||||||
\ 'coffee'
|
\ 'coffee'
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
" Description: coffeelint linter for coffeescript files
|
" Description: coffeelint linter for coffeescript files
|
||||||
|
|
||||||
function! ale_linters#coffee#coffeelint#GetExecutable(buffer) abort
|
function! ale_linters#coffee#coffeelint#GetExecutable(buffer) abort
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/coffeelint',
|
\ 'node_modules/.bin/coffeelint',
|
||||||
\ 'coffeelint'
|
\ 'coffeelint'
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
" Description: This file adds support for checking CSS code with csslint.
|
" Description: This file adds support for checking CSS code with csslint.
|
||||||
|
|
||||||
function! ale_linters#css#csslint#GetCommand(buffer) abort
|
function! ale_linters#css#csslint#GetCommand(buffer) abort
|
||||||
let l:csslintrc = ale#util#FindNearestFile(a:buffer, '.csslintrc')
|
let l:csslintrc = ale#path#FindNearestFile(a:buffer, '.csslintrc')
|
||||||
let l:config_option = !empty(l:csslintrc)
|
let l:config_option = !empty(l:csslintrc)
|
||||||
\ ? '--config=' . fnameescape(l:csslintrc)
|
\ ? '--config=' . fnameescape(l:csslintrc)
|
||||||
\ : ''
|
\ : ''
|
||||||
|
@ -14,7 +14,7 @@ function! ale_linters#css#stylelint#GetExecutable(buffer) abort
|
|||||||
return ale#Var(a:buffer, 'css_stylelint_executable')
|
return ale#Var(a:buffer, 'css_stylelint_executable')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/stylelint',
|
\ 'node_modules/.bin/stylelint',
|
||||||
\ ale#Var(a:buffer, 'css_stylelint_executable')
|
\ ale#Var(a:buffer, 'css_stylelint_executable')
|
||||||
|
@ -5,7 +5,7 @@ function! s:FindDUBConfig(buffer) abort
|
|||||||
" Find a DUB configuration file in ancestor paths.
|
" Find a DUB configuration file in ancestor paths.
|
||||||
" The most DUB-specific names will be tried first.
|
" The most DUB-specific names will be tried first.
|
||||||
for l:possible_filename in ['dub.sdl', 'dub.json', 'package.json']
|
for l:possible_filename in ['dub.sdl', 'dub.json', 'package.json']
|
||||||
let l:dub_file = ale#util#FindNearestFile(a:buffer, l:possible_filename)
|
let l:dub_file = ale#path#FindNearestFile(a:buffer, l:possible_filename)
|
||||||
|
|
||||||
if !empty(l:dub_file)
|
if !empty(l:dub_file)
|
||||||
return l:dub_file
|
return l:dub_file
|
||||||
|
@ -38,7 +38,7 @@ endfunction
|
|||||||
" Return the command to execute the linter in the projects directory.
|
" Return the command to execute the linter in the projects directory.
|
||||||
" If it doesn't, then this will fail when imports are needed.
|
" If it doesn't, then this will fail when imports are needed.
|
||||||
function! ale_linters#elm#make#GetCommand(buffer) abort
|
function! ale_linters#elm#make#GetCommand(buffer) abort
|
||||||
let l:elm_package = ale#util#FindNearestFile(a:buffer, 'elm-package.json')
|
let l:elm_package = ale#path#FindNearestFile(a:buffer, 'elm-package.json')
|
||||||
if empty(l:elm_package)
|
if empty(l:elm_package)
|
||||||
let l:dir_set_cmd = ''
|
let l:dir_set_cmd = ''
|
||||||
else
|
else
|
||||||
|
@ -12,7 +12,7 @@ function! ale_linters#handlebars#embertemplatelint#GetExecutable(buffer) abort
|
|||||||
return ale#Var(a:buffer, 'handlebars_embertemplatelint_executable')
|
return ale#Var(a:buffer, 'handlebars_embertemplatelint_executable')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/ember-template-lint',
|
\ 'node_modules/.bin/ember-template-lint',
|
||||||
\ ale#Var(a:buffer, 'handlebars_embertemplatelint_executable')
|
\ ale#Var(a:buffer, 'handlebars_embertemplatelint_executable')
|
||||||
|
@ -11,7 +11,7 @@ function! ale_linters#html#htmlhint#GetExecutable(buffer) abort
|
|||||||
return ale#Var(a:buffer, 'html_htmlhint_executable')
|
return ale#Var(a:buffer, 'html_htmlhint_executable')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/htmlhint',
|
\ 'node_modules/.bin/htmlhint',
|
||||||
\ ale#Var(a:buffer, 'html_htmlhint_executable')
|
\ ale#Var(a:buffer, 'html_htmlhint_executable')
|
||||||
|
@ -16,7 +16,7 @@ function! ale_linters#javascript#eslint#GetExecutable(buffer) abort
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
" Look for the kinds of paths that create-react-app generates first.
|
" Look for the kinds of paths that create-react-app generates first.
|
||||||
let l:executable = ale#util#ResolveLocalPath(
|
let l:executable = ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/eslint/bin/eslint.js',
|
\ 'node_modules/eslint/bin/eslint.js',
|
||||||
\ ''
|
\ ''
|
||||||
@ -26,7 +26,7 @@ function! ale_linters#javascript#eslint#GetExecutable(buffer) abort
|
|||||||
return l:executable
|
return l:executable
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/eslint',
|
\ 'node_modules/.bin/eslint',
|
||||||
\ ale#Var(a:buffer, 'javascript_eslint_executable')
|
\ ale#Var(a:buffer, 'javascript_eslint_executable')
|
||||||
|
@ -12,7 +12,7 @@ function! ale_linters#javascript#flow#GetExecutable(buffer) abort
|
|||||||
return ale#Var(a:buffer, 'javascript_flow_executable')
|
return ale#Var(a:buffer, 'javascript_flow_executable')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/flow',
|
\ 'node_modules/.bin/flow',
|
||||||
\ ale#Var(a:buffer, 'javascript_flow_executable')
|
\ ale#Var(a:buffer, 'javascript_flow_executable')
|
||||||
@ -20,7 +20,7 @@ function! ale_linters#javascript#flow#GetExecutable(buffer) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#javascript#flow#GetCommand(buffer) abort
|
function! ale_linters#javascript#flow#GetCommand(buffer) abort
|
||||||
let l:flow_config = ale#util#FindNearestFile(a:buffer, '.flowconfig')
|
let l:flow_config = ale#path#FindNearestFile(a:buffer, '.flowconfig')
|
||||||
|
|
||||||
if empty(l:flow_config)
|
if empty(l:flow_config)
|
||||||
" Don't run Flow if we can't find a .flowconfig file.
|
" Don't run Flow if we can't find a .flowconfig file.
|
||||||
|
@ -12,7 +12,7 @@ function! ale_linters#javascript#jshint#GetExecutable(buffer) abort
|
|||||||
return ale#Var(a:buffer, 'javascript_jshint_executable')
|
return ale#Var(a:buffer, 'javascript_jshint_executable')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/jshint',
|
\ 'node_modules/.bin/jshint',
|
||||||
\ ale#Var(a:buffer, 'javascript_jshint_executable')
|
\ ale#Var(a:buffer, 'javascript_jshint_executable')
|
||||||
@ -21,7 +21,7 @@ endfunction
|
|||||||
|
|
||||||
function! ale_linters#javascript#jshint#GetCommand(buffer) abort
|
function! ale_linters#javascript#jshint#GetCommand(buffer) abort
|
||||||
" Search for a local JShint config locaation, and default to a global one.
|
" Search for a local JShint config locaation, and default to a global one.
|
||||||
let l:jshint_config = ale#util#ResolveLocalPath(
|
let l:jshint_config = ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ '.jshintrc',
|
\ '.jshintrc',
|
||||||
\ get(g:, 'ale_jshint_config_loc', '')
|
\ get(g:, 'ale_jshint_config_loc', '')
|
||||||
|
@ -15,7 +15,7 @@ function! ale_linters#javascript#standard#GetExecutable(buffer) abort
|
|||||||
return ale#Var(a:buffer, 'javascript_standard_executable')
|
return ale#Var(a:buffer, 'javascript_standard_executable')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/standard',
|
\ 'node_modules/.bin/standard',
|
||||||
\ ale#Var(a:buffer, 'javascript_standard_executable')
|
\ ale#Var(a:buffer, 'javascript_standard_executable')
|
||||||
|
@ -15,7 +15,7 @@ function! ale_linters#javascript#xo#GetExecutable(buffer) abort
|
|||||||
return g:ale_javascript_xo_executable
|
return g:ale_javascript_xo_executable
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/xo',
|
\ 'node_modules/.bin/xo',
|
||||||
\ g:ale_javascript_xo_executable
|
\ g:ale_javascript_xo_executable
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
let g:ale_python_mypy_options = get(g:, 'ale_python_mypy_options', '')
|
let g:ale_python_mypy_options = get(g:, 'ale_python_mypy_options', '')
|
||||||
|
|
||||||
function! ale_linters#python#mypy#GetCommand(buffer) abort
|
function! ale_linters#python#mypy#GetCommand(buffer) abort
|
||||||
let l:automatic_stubs_dir = ale#util#FindNearestDirectory(a:buffer, 'stubs')
|
let l:automatic_stubs_dir = ale#path#FindNearestDirectory(a:buffer, 'stubs')
|
||||||
" TODO: Add Windows support
|
" TODO: Add Windows support
|
||||||
let l:automatic_stubs_command = (has('unix') && !empty(l:automatic_stubs_dir))
|
let l:automatic_stubs_command = (has('unix') && !empty(l:automatic_stubs_dir))
|
||||||
\ ? 'MYPYPATH=' . l:automatic_stubs_dir . ' '
|
\ ? 'MYPYPATH=' . l:automatic_stubs_dir . ' '
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
let g:ale_rust_cargo_use_check = get(g:, 'ale_rust_cargo_use_check', 0)
|
let g:ale_rust_cargo_use_check = get(g:, 'ale_rust_cargo_use_check', 0)
|
||||||
|
|
||||||
function! ale_linters#rust#cargo#GetCargoExecutable(bufnr) abort
|
function! ale_linters#rust#cargo#GetCargoExecutable(bufnr) abort
|
||||||
if ale#util#FindNearestFile(a:bufnr, 'Cargo.toml') !=# ''
|
if ale#path#FindNearestFile(a:bufnr, 'Cargo.toml') !=# ''
|
||||||
return 'cargo'
|
return 'cargo'
|
||||||
else
|
else
|
||||||
" if there is no Cargo.toml file, we don't use cargo even if it exists,
|
" if there is no Cargo.toml file, we don't use cargo even if it exists,
|
||||||
|
@ -5,7 +5,7 @@ function! ale_linters#rust#rustc#RustcCommand(buffer_number) abort
|
|||||||
" Try to guess the library search path. If the project is managed by cargo,
|
" Try to guess the library search path. If the project is managed by cargo,
|
||||||
" it's usually <project root>/target/debug/deps/ or
|
" it's usually <project root>/target/debug/deps/ or
|
||||||
" <project root>/target/release/deps/
|
" <project root>/target/release/deps/
|
||||||
let l:cargo_file = ale#util#FindNearestFile(a:buffer_number, 'Cargo.toml')
|
let l:cargo_file = ale#path#FindNearestFile(a:buffer_number, 'Cargo.toml')
|
||||||
|
|
||||||
if l:cargo_file !=# ''
|
if l:cargo_file !=# ''
|
||||||
let l:project_root = fnamemodify(l:cargo_file, ':h')
|
let l:project_root = fnamemodify(l:cargo_file, ':h')
|
||||||
|
@ -11,7 +11,7 @@ function! ale_linters#sass#stylelint#GetExecutable(buffer) abort
|
|||||||
return ale#Var(a:buffer, 'sass_stylelint_executable')
|
return ale#Var(a:buffer, 'sass_stylelint_executable')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/stylelint',
|
\ 'node_modules/.bin/stylelint',
|
||||||
\ ale#Var(a:buffer, 'sass_stylelint_executable')
|
\ ale#Var(a:buffer, 'sass_stylelint_executable')
|
||||||
|
@ -11,7 +11,7 @@ function! ale_linters#scss#stylelint#GetExecutable(buffer) abort
|
|||||||
return ale#Var(a:buffer, 'scss_stylelint_executable')
|
return ale#Var(a:buffer, 'scss_stylelint_executable')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/stylelint',
|
\ 'node_modules/.bin/stylelint',
|
||||||
\ ale#Var(a:buffer, 'scss_stylelint_executable')
|
\ ale#Var(a:buffer, 'scss_stylelint_executable')
|
||||||
|
@ -9,7 +9,7 @@ let g:ale_tex_chktex_options =
|
|||||||
|
|
||||||
function! ale_linters#tex#chktex#GetCommand(buffer) abort
|
function! ale_linters#tex#chktex#GetCommand(buffer) abort
|
||||||
" Check for optional .chktexrc
|
" Check for optional .chktexrc
|
||||||
let l:chktex_config = ale#util#FindNearestFile(
|
let l:chktex_config = ale#path#FindNearestFile(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ '.chktexrc')
|
\ '.chktexrc')
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ let g:ale_typescript_tslint_config_path =
|
|||||||
\ get(g:, 'ale_typescript_tslint_config_path', '')
|
\ get(g:, 'ale_typescript_tslint_config_path', '')
|
||||||
|
|
||||||
function! ale_linters#typescript#tslint#GetExecutable(buffer) abort
|
function! ale_linters#typescript#tslint#GetExecutable(buffer) abort
|
||||||
return ale#util#ResolveLocalPath(
|
return ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'node_modules/.bin/tslint',
|
\ 'node_modules/.bin/tslint',
|
||||||
\ ale#Var(a:buffer, 'typescript_tslint_executable')
|
\ ale#Var(a:buffer, 'typescript_tslint_executable')
|
||||||
@ -50,7 +50,7 @@ function! ale_linters#typescript#tslint#Handle(buffer, lines) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#typescript#tslint#BuildLintCommand(buffer) abort
|
function! ale_linters#typescript#tslint#BuildLintCommand(buffer) abort
|
||||||
let l:tslint_config_path = ale#util#ResolveLocalPath(
|
let l:tslint_config_path = ale#path#ResolveLocalPath(
|
||||||
\ a:buffer,
|
\ a:buffer,
|
||||||
\ 'tslint.json',
|
\ 'tslint.json',
|
||||||
\ ale#Var(a:buffer, 'typescript_tslint_config_path')
|
\ ale#Var(a:buffer, 'typescript_tslint_config_path')
|
||||||
|
57
autoload/ale/path.vim
Normal file
57
autoload/ale/path.vim
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
" Author: w0rp <devw0rp@gmail.com>
|
||||||
|
" Description: Functions for working with paths in the filesystem.
|
||||||
|
|
||||||
|
" Given a buffer and a filename, find the nearest file by searching upwards
|
||||||
|
" through the paths relative to the given buffer.
|
||||||
|
function! ale#path#FindNearestFile(buffer, filename) abort
|
||||||
|
let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p')
|
||||||
|
|
||||||
|
let l:relative_path = findfile(a:filename, l:buffer_filename . ';')
|
||||||
|
|
||||||
|
if !empty(l:relative_path)
|
||||||
|
return fnamemodify(l:relative_path, ':p')
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Given a buffer and a directory name, find the nearest directory by searching upwards
|
||||||
|
" through the paths relative to the given buffer.
|
||||||
|
function! ale#path#FindNearestDirectory(buffer, directory_name) abort
|
||||||
|
let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p')
|
||||||
|
|
||||||
|
let l:relative_path = finddir(a:directory_name, l:buffer_filename . ';')
|
||||||
|
|
||||||
|
if !empty(l:relative_path)
|
||||||
|
return fnamemodify(l:relative_path, ':p')
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Given a buffer, a string to search for, an a global fallback for when
|
||||||
|
" the search fails, look for a file in parent paths, and if that fails,
|
||||||
|
" use the global fallback path instead.
|
||||||
|
function! ale#path#ResolveLocalPath(buffer, search_string, global_fallback) abort
|
||||||
|
" Search for a locally installed file first.
|
||||||
|
let l:path = ale#path#FindNearestFile(a:buffer, a:search_string)
|
||||||
|
|
||||||
|
" If the serach fails, try the global executable instead.
|
||||||
|
if empty(l:path)
|
||||||
|
let l:path = a:global_fallback
|
||||||
|
endif
|
||||||
|
|
||||||
|
return l:path
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Output 'cd <directory> && '
|
||||||
|
" This function can be used changing the directory for a linter command.
|
||||||
|
function! ale#path#CdString(directory) abort
|
||||||
|
return 'cd ' . fnameescape(a:directory) . ' && '
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Output 'cd <buffer_filename_directory> && '
|
||||||
|
" This function can be used changing the directory for a linter command.
|
||||||
|
function! ale#path#BufferCdString(buffer) abort
|
||||||
|
return ale#path#CdString(fnamemodify(bufname(a:buffer), ':p:h'))
|
||||||
|
endfunction
|
@ -13,49 +13,6 @@ function! ale#util#GetLineCount(buffer) abort
|
|||||||
return len(getbufline(a:buffer, 1, '$'))
|
return len(getbufline(a:buffer, 1, '$'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Given a buffer and a filename, find the nearest file by searching upwards
|
|
||||||
" through the paths relative to the given buffer.
|
|
||||||
function! ale#util#FindNearestFile(buffer, filename) abort
|
|
||||||
let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p')
|
|
||||||
|
|
||||||
let l:relative_path = findfile(a:filename, l:buffer_filename . ';')
|
|
||||||
|
|
||||||
if !empty(l:relative_path)
|
|
||||||
return fnamemodify(l:relative_path, ':p')
|
|
||||||
endif
|
|
||||||
|
|
||||||
return ''
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Given a buffer and a directory name, find the nearest directory by searching upwards
|
|
||||||
" through the paths relative to the given buffer.
|
|
||||||
function! ale#util#FindNearestDirectory(buffer, directory_name) abort
|
|
||||||
let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p')
|
|
||||||
|
|
||||||
let l:relative_path = finddir(a:directory_name, l:buffer_filename . ';')
|
|
||||||
|
|
||||||
if !empty(l:relative_path)
|
|
||||||
return fnamemodify(l:relative_path, ':p')
|
|
||||||
endif
|
|
||||||
|
|
||||||
return ''
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Given a buffer, a string to search for, an a global fallback for when
|
|
||||||
" the search fails, look for a file in parent paths, and if that fails,
|
|
||||||
" use the global fallback path instead.
|
|
||||||
function! ale#util#ResolveLocalPath(buffer, search_string, global_fallback) abort
|
|
||||||
" Search for a locally installed file first.
|
|
||||||
let l:path = ale#util#FindNearestFile(a:buffer, a:search_string)
|
|
||||||
|
|
||||||
" If the serach fails, try the global executable instead.
|
|
||||||
if empty(l:path)
|
|
||||||
let l:path = a:global_fallback
|
|
||||||
endif
|
|
||||||
|
|
||||||
return l:path
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! ale#util#GetFunction(string_or_ref) abort
|
function! ale#util#GetFunction(string_or_ref) abort
|
||||||
if type(a:string_or_ref) == type('')
|
if type(a:string_or_ref) == type('')
|
||||||
return function(a:string_or_ref)
|
return function(a:string_or_ref)
|
||||||
@ -144,16 +101,3 @@ endfunction
|
|||||||
function! ale#util#ClockMilliseconds() abort
|
function! ale#util#ClockMilliseconds() abort
|
||||||
return float2nr(reltimefloat(reltime()) * 1000)
|
return float2nr(reltimefloat(reltime()) * 1000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
" Output 'cd <directory> && '
|
|
||||||
" This function can be used changing the directory for a linter command.
|
|
||||||
function! ale#util#CdString(directory) abort
|
|
||||||
return 'cd ' . fnameescape(a:directory) . ' && '
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Output 'cd <buffer_filename_directory> && '
|
|
||||||
" This function can be used changing the directory for a linter command.
|
|
||||||
function! ale#util#BufferCdString(buffer) abort
|
|
||||||
return ale#util#CdString(fnamemodify(bufname(a:buffer), ':p:h'))
|
|
||||||
endfunction
|
|
||||||
|
@ -5,11 +5,11 @@ Execute(Open a file some directory down):
|
|||||||
Then(We should be able to find the right directory):
|
Then(We should be able to find the right directory):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ expand('%:p:h:h:h:h') . '/top/ale-special-directory-name-dont-use-this-please/',
|
\ expand('%:p:h:h:h:h') . '/top/ale-special-directory-name-dont-use-this-please/',
|
||||||
\ ale#util#FindNearestDirectory(bufnr('%'), 'ale-special-directory-name-dont-use-this-please')
|
\ ale#path#FindNearestDirectory(bufnr('%'), 'ale-special-directory-name-dont-use-this-please')
|
||||||
|
|
||||||
Execute(Do nothing):
|
Execute(Do nothing):
|
||||||
|
|
||||||
Then(We shouldn't find anything for files which don't match):
|
Then(We shouldn't find anything for files which don't match):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ '',
|
\ '',
|
||||||
\ ale#util#FindNearestDirectory(bufnr('%'), 'ale-this-should-never-match-anything')
|
\ ale#path#FindNearestDirectory(bufnr('%'), 'ale-this-should-never-match-anything')
|
||||||
|
@ -3,9 +3,9 @@ Execute(Open a file some directory down):
|
|||||||
:e! top/middle/bottom/dummy.txt
|
:e! top/middle/bottom/dummy.txt
|
||||||
|
|
||||||
Then(We should be able to find a configuration file further up):
|
Then(We should be able to find a configuration file further up):
|
||||||
AssertEqual expand('%:p:h:h:h:h') . '/top/example.ini', ale#util#FindNearestFile(bufnr('%'), 'example.ini')
|
AssertEqual expand('%:p:h:h:h:h') . '/top/example.ini', ale#path#FindNearestFile(bufnr('%'), 'example.ini')
|
||||||
|
|
||||||
Execute(Do nothing):
|
Execute(Do nothing):
|
||||||
|
|
||||||
Then(We shouldn't find anything for files which don't match):
|
Then(We shouldn't find anything for files which don't match):
|
||||||
AssertEqual '', ale#util#FindNearestFile(bufnr('%'), 'cantfindthis')
|
AssertEqual '', ale#path#FindNearestFile(bufnr('%'), 'cantfindthis')
|
||||||
|
@ -5,11 +5,11 @@ Execute(Open a file some directory down):
|
|||||||
Then(We should be able to find the local version of a file):
|
Then(We should be able to find the local version of a file):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ expand('%:p:h:h:h:h') . '/top/example.ini',
|
\ expand('%:p:h:h:h:h') . '/top/example.ini',
|
||||||
\ ale#util#ResolveLocalPath(bufnr('%'), 'example.ini', '/global/config.ini')
|
\ ale#path#ResolveLocalPath(bufnr('%'), 'example.ini', '/global/config.ini')
|
||||||
|
|
||||||
Execute(Do nothing):
|
Execute(Do nothing):
|
||||||
|
|
||||||
Then(We shouldn't find anything for files which don't match):
|
Then(We shouldn't find anything for files which don't match):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ '/global/config.ini',
|
\ '/global/config.ini',
|
||||||
\ ale#util#ResolveLocalPath(bufnr('%'), 'missing.ini', '/global/config.ini')
|
\ ale#path#ResolveLocalPath(bufnr('%'), 'missing.ini', '/global/config.ini')
|
||||||
|
@ -2,8 +2,8 @@ Before:
|
|||||||
silent! cd /testplugin/test/util
|
silent! cd /testplugin/test/util
|
||||||
|
|
||||||
Execute(CdString should output the correct command string):
|
Execute(CdString should output the correct command string):
|
||||||
AssertEqual 'cd /foo\ bar/baz && ', ale#util#CdString('/foo bar/baz')
|
AssertEqual 'cd /foo\ bar/baz && ', ale#path#CdString('/foo bar/baz')
|
||||||
|
|
||||||
Execute(BufferCdString should output the correct command string):
|
Execute(BufferCdString should output the correct command string):
|
||||||
Assert match(ale#util#BufferCdString(bufnr('')), '^cd .*test/util && $') >= 0,
|
Assert match(ale#path#BufferCdString(bufnr('')), '^cd .*test/util && $') >= 0,
|
||||||
\ 'String didn''t match regex: ' . ale#util#BufferCdString(bufnr(''))
|
\ 'String didn''t match regex: ' . ale#path#BufferCdString(bufnr(''))
|
||||||
|
Loading…
Reference in New Issue
Block a user