diff options
author | w0rp <devw0rp@gmail.com> | 2019-06-05 14:16:43 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2019-06-05 14:16:43 +0100 |
commit | 7b78f2b846e2f3443dcb2ceacee54eb99e37f040 (patch) | |
tree | 3173fbc32daa56a25fb3de28470fdcaf381e32c0 | |
parent | 381fff0e4c0c7c5057ed0d114169fac3a419ff85 (diff) | |
download | ale-7b78f2b846e2f3443dcb2ceacee54eb99e37f040.zip |
Fix #2525 - Convert Windows paths in a Unix environment
-rw-r--r-- | autoload/ale/path.vim | 11 | ||||
-rw-r--r-- | test/handler/test_mypy_handler.vader | 2 | ||||
-rw-r--r-- | test/test_path_equality.vader | 27 |
3 files changed, 37 insertions, 3 deletions
diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim index 60d42eb5..84c26d0a 100644 --- a/autoload/ale/path.vim +++ b/autoload/ale/path.vim @@ -3,13 +3,20 @@ " simplify a path, and fix annoying issues with paths on Windows. " -" Forward slashes are changed to back slashes so path equality works better. +" Forward slashes are changed to back slashes so path equality works better +" on Windows. Back slashes are changed to forward slashes on Unix. +" +" Unix paths can technically contain back slashes, but in practice no path +" should, and replacing back slashes with forward slashes makes linters work +" in environments like MSYS. " " Paths starting with more than one forward slash are changed to only one " forward slash, to prevent the paths being treated as special MSYS paths. function! ale#path#Simplify(path) abort if has('unix') - return substitute(simplify(a:path), '^//\+', '/', 'g') " no-custom-checks + let l:unix_path = substitute(a:path, '\\', '/', 'g') + + return substitute(simplify(l:unix_path), '^//\+', '/', 'g') " no-custom-checks endif let l:win_path = substitute(a:path, '/', '\\', 'g') diff --git a/test/handler/test_mypy_handler.vader b/test/handler/test_mypy_handler.vader index f3d4cbf8..6e96f3f3 100644 --- a/test/handler/test_mypy_handler.vader +++ b/test/handler/test_mypy_handler.vader @@ -78,7 +78,7 @@ Execute(The mypy handler should handle Windows names with spaces): \ { \ 'lnum': 4, \ 'col': 0, - \ 'filename': 'C:\something\with spaces.py', + \ 'filename': ale#path#Simplify('C:\something\with spaces.py'), \ 'type': 'E', \ 'text': 'No library stub file for module ''django.db''', \ }, diff --git a/test/test_path_equality.vader b/test/test_path_equality.vader index 4ec9bd64..ee6ae2c5 100644 --- a/test/test_path_equality.vader +++ b/test/test_path_equality.vader @@ -6,6 +6,22 @@ Before: After: delfunction CheckPath +Execute(ale#path#Simplify should adjust paths correctly): + if has('unix') + " Multiple slashes should be removed correctly. + AssertEqual '/foo/bar/baz', ale#path#Simplify('////foo///bar///baz') + " Back slashes should be converted to forward slashes. + " This means some valid filenames are adjusted incorrectly, but in practice + " no filenames for code should contain back slashes, and adjusting slashes + " like this makes ALE work in MSYS. + AssertEqual 'foo/bar/baz', ale#path#Simplify('foo\bar\baz') + else + " Multiple slashes should be removed correctly. + AssertEqual '\foo\bar\baz', ale#path#Simplify('\\\foo\bar\baz') + " Forward slashes should be replaced with back slashes. + AssertEqual 'foo\bar\baz', ale#path#Simplify('foo/bar/baz') + endif + Execute(ale#path#IsBufferPath should match simple relative paths): call ale#test#SetFilename('app/foo.txt') @@ -53,3 +69,14 @@ Execute(ale#path#IsBufferPath should match files in /tmp): call ale#test#SetFilename('app/test.ts') Assert ale#path#IsBufferPath(bufnr(''), tempname() . '/test.ts') + +Execute(ale#path#IsBufferPath should match Windows paths on Unix): + " This test should pass Unix. + " + " Back slashes in paths should be replaced with forward slashes, even though + " back slashes are valid in filenames on Unix. + if has('unix') + call ale#test#SetFilename('app/foo/test.ts') + + Assert ale#path#IsBufferPath(bufnr(''), 'foo\test.ts') + endif |