diff options
author | w0rp <devw0rp@gmail.com> | 2017-09-14 00:11:17 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-09-14 00:11:17 +0100 |
commit | a59d1ddbf39fac6463c3b8748faf2651c9f9130d (patch) | |
tree | 0dd1f6c5736ee93be00b06eec3dcdcc517ffb633 | |
parent | 71c2e65d6468bbbc2d08236d7dda0e3876613822 (diff) | |
download | ale-a59d1ddbf39fac6463c3b8748faf2651c9f9130d.zip |
Make temporary file detection work on just about all platforms
-rw-r--r-- | autoload/ale/engine.vim | 2 | ||||
-rw-r--r-- | autoload/ale/path.vim | 16 | ||||
-rw-r--r-- | test/handler/test_ansible_lint_handler.vader | 4 | ||||
-rw-r--r-- | test/test_path_equality.vader | 7 |
4 files changed, 7 insertions, 22 deletions
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index c49bc9b8..839218b4 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -375,7 +375,7 @@ function! ale#engine#FixLocList(buffer, linter_name, loclist) abort \} if has_key(l:old_item, 'filename') - \&& l:old_item.filename[:len(s:temp_dir) - 1] isnot# s:temp_dir + \&& !ale#path#IsTempName(l:old_item.filename) " Use the filename given. " Temporary files are assumed to be for this buffer, " and the filename is not included then, because it looks bad diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim index 7ad34b58..0ba174c7 100644 --- a/autoload/ale/path.vim +++ b/autoload/ale/path.vim @@ -80,22 +80,12 @@ function! ale#path#IsAbsolute(filename) abort return a:filename[:0] is# '/' || a:filename[1:2] is# ':\' endfunction +let s:temp_dir = fnamemodify(tempname(), ':h') + " Given a filename, return 1 if the file represents some temporary file " created by Vim. function! ale#path#IsTempName(filename) abort - let l:prefix_list = [ - \ $TMPDIR, - \ resolve($TMPDIR), - \ '/run/user', - \] - - for l:prefix in l:prefix_list - if a:filename[:len(l:prefix) - 1] is# l:prefix - return 1 - endif - endfor - - return 0 + return a:filename[:len(s:temp_dir) - 1] is# s:temp_dir endfunction " Given a base directory, which must not have a trailing slash, and a diff --git a/test/handler/test_ansible_lint_handler.vader b/test/handler/test_ansible_lint_handler.vader index b14b1f63..3a86429c 100644 --- a/test/handler/test_ansible_lint_handler.vader +++ b/test/handler/test_ansible_lint_handler.vader @@ -16,7 +16,7 @@ Execute(The ansible-lint handler should handle basic errors): \ }, \ ], \ ale_linters#ansible#ansible_lint#Handle(bufnr(''), [ - \ '/tmp/vxepmGL/1/main.yml:35: [EANSIBLE0002] Trailing whitespace', + \ fnamemodify(tempname(), ':h') . '/main.yml:35: [EANSIBLE0002] Trailing whitespace', \ ]) Execute (The ansible-lint handler should handle names with spaces): @@ -30,7 +30,7 @@ Execute (The ansible-lint handler should handle names with spaces): \ }, \ ], \ ale_linters#ansible#ansible_lint#Handle(bufnr(''), [ - \ '/tmp/vxepm GL/1/main.yml:6:6: E111 indentation is not a multiple of four', + \ fnamemodify(tempname(), ':h') . '/main.yml:6:6: E111 indentation is not a multiple of four', \ ]) Execute (The ansible-lint handler should ignore errors from other files): diff --git a/test/test_path_equality.vader b/test/test_path_equality.vader index c17f0010..314a2d9b 100644 --- a/test/test_path_equality.vader +++ b/test/test_path_equality.vader @@ -52,9 +52,4 @@ Execute(ale#path#IsBufferPath should accept various names for stdin): Execute(ale#path#IsBufferPath should match files in /tmp): call ale#test#SetFilename('app/test.ts') - " Skip these checks on Windows. - if !has('win32') - Assert ale#path#IsBufferPath(bufnr(''), '../../../../../../../../tmp/vG0hKyD/1/test.ts') - Assert ale#path#IsBufferPath(bufnr(''), '/tmp/vG0hKyD/1/test.ts') - Assert ale#path#IsBufferPath(bufnr(''), '/run/user/1000/vG0hKyD/1/test.ts') - endif + Assert ale#path#IsBufferPath(bufnr(''), tempname() . '/test.ts') |