diff --git a/autoload/ale/fixers/autopep8.vim b/autoload/ale/fixers/autopep8.vim index e2dd7bf..e0e6205 100644 --- a/autoload/ale/fixers/autopep8.vim +++ b/autoload/ale/fixers/autopep8.vim @@ -12,7 +12,7 @@ function! ale#fixers#autopep8#Fix(buffer) abort \ ['autopep8'], \) - if !executable(l:executable) + if !ale#python#IsExecutable(l:executable) return 0 endif diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim index 00d968f..ddd9561 100644 --- a/autoload/ale/fixers/isort.vim +++ b/autoload/ale/fixers/isort.vim @@ -11,7 +11,7 @@ function! ale#fixers#isort#Fix(buffer) abort \ ['isort'], \) - if !executable(l:executable) + if !ale#python#IsExecutable(l:executable) return 0 endif diff --git a/autoload/ale/fixers/standard.vim b/autoload/ale/fixers/standard.vim index 443560e..c998cfd 100644 --- a/autoload/ale/fixers/standard.vim +++ b/autoload/ale/fixers/standard.vim @@ -1,6 +1,10 @@ " Author: Sumner Evans " Description: Fixing files with Standard. +call ale#Set('javascript_standard_executable', 'standard') +call ale#Set('javascript_standard_use_global', 0) +call ale#Set('javascript_standard_options', '') + function! ale#fixers#standard#GetExecutable(buffer) abort return ale#node#FindExecutable(a:buffer, 'javascript_standard', [ \ 'node_modules/standard/bin/cmd.js', diff --git a/autoload/ale/handlers/eslint.vim b/autoload/ale/handlers/eslint.vim index b08e0ea..3397ab5 100644 --- a/autoload/ale/handlers/eslint.vim +++ b/autoload/ale/handlers/eslint.vim @@ -1,6 +1,8 @@ " Author: w0rp " Description: Functions for working with eslint, for checking or fixing files. +let s:sep = has('win32') ? '\' : '/' + call ale#Set('javascript_eslint_options', '') call ale#Set('javascript_eslint_executable', 'eslint') call ale#Set('javascript_eslint_use_global', 0) @@ -15,7 +17,7 @@ function! ale#handlers#eslint#FindConfig(buffer) abort \ '.eslintrc.json', \ '.eslintrc', \] - let l:config = ale#path#Simplify(l:path . '/' . l:basename) + let l:config = ale#path#Simplify(join([l:path, l:basename], s:sep)) if filereadable(l:config) return l:config diff --git a/test/fixers/test_autopep8_fixer_callback.vader b/test/fixers/test_autopep8_fixer_callback.vader index c8c0bd4..600fb19 100644 --- a/test/fixers/test_autopep8_fixer_callback.vader +++ b/test/fixers/test_autopep8_fixer_callback.vader @@ -11,9 +11,13 @@ Before: silent cd command_callback let g:dir = getcwd() + let b:bin_dir = has('win32') ? 'Scripts' : 'bin' + After: Restore + unlet! b:bin_dir + call ale#test#RestoreDirectory() Execute(The autopep8 callback should return the correct default values): @@ -23,7 +27,7 @@ Execute(The autopep8 callback should return the correct default values): silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py') AssertEqual - \ {'command': "'" . g:dir . "/python_paths/with_virtualenv/env/bin/autopep8' -" }, + \ {'command': ale#Escape(ale#path#Winify(g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/autopep8')) . ' -'}, \ ale#fixers#autopep8#Fix(bufnr('')) Execute(The autopep8 callback should include options): @@ -31,5 +35,5 @@ Execute(The autopep8 callback should include options): silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py') AssertEqual - \ {'command': "'" . g:dir . "/python_paths/with_virtualenv/env/bin/autopep8' --some-option -" }, + \ {'command': ale#Escape(ale#path#Winify(g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/autopep8')) . ' --some-option -' }, \ ale#fixers#autopep8#Fix(bufnr('')) diff --git a/test/fixers/test_elm_format_fixer_callback.vader b/test/fixers/test_elm_format_fixer_callback.vader index b8b9ed0..8552c5d 100644 --- a/test/fixers/test_elm_format_fixer_callback.vader +++ b/test/fixers/test_elm_format_fixer_callback.vader @@ -15,7 +15,7 @@ Execute(The elm-format command should have default params): \ { \ 'read_temporary_file': 1, \ 'command': - \ ale#Escape(simplify(g:dir . '/../elm-test-files/node_modules/.bin/elm-format')) + \ ale#Escape(ale#path#Winify(g:dir . '/../elm-test-files/node_modules/.bin/elm-format')) \ . ' %t --yes', \ }, \ ale#fixers#format#Fix(bufnr('')) @@ -55,7 +55,7 @@ Execute(The elm-format command should manage empty options): \ { \ 'read_temporary_file': 1, \ 'command': - \ ale#Escape(simplify(g:dir . '/../elm-test-files/node_modules/.bin/elm-format')) + \ ale#Escape(ale#path#Winify(g:dir . '/../elm-test-files/node_modules/.bin/elm-format')) \ . ' %t', \ }, \ ale#fixers#format#Fix(bufnr('')) @@ -68,8 +68,7 @@ Execute(The elm-format command should manage custom options): \ { \ 'read_temporary_file': 1, \ 'command': - \ ale#Escape(simplify(g:dir . '/../elm-test-files/node_modules/.bin/elm-format')) + \ ale#Escape(ale#path#Winify(g:dir . '/../elm-test-files/node_modules/.bin/elm-format')) \ . ' %t --param1 --param2', \ }, \ ale#fixers#format#Fix(bufnr('')) - diff --git a/test/fixers/test_eslint_fixer_callback.vader b/test/fixers/test_eslint_fixer_callback.vader index 21eb450..d4783fc 100644 --- a/test/fixers/test_eslint_fixer_callback.vader +++ b/test/fixers/test_eslint_fixer_callback.vader @@ -2,18 +2,17 @@ Before: call ale#test#SetDirectory('/testplugin/test/fixers') After: - let g:ale_has_override = {} call ale#test#RestoreDirectory() -Execute(The path to eslint.js should be run on Unix): +Execute(The executable path should be correct): call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') AssertEqual \ { \ 'read_temporary_file': 1, - \ 'command': - \ ale#Escape(simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) - \ . ' -c ' . ale#Escape(simplify(g:dir . '/../eslint-test-files/react-app/.eslintrc.js')) + \ 'command': (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) + \ . ' -c ' . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/.eslintrc.js')) \ . ' --fix %t', \ }, \ ale#fixers#eslint#Fix(bufnr('')) @@ -24,9 +23,9 @@ Execute(The lower priority configuration file in a nested directory should be pr AssertEqual \ { \ 'read_temporary_file': 1, - \ 'command': - \ ale#Escape(simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) - \ . ' -c ' . ale#Escape(simplify(g:dir . '/../eslint-test-files/react-app/subdir-with-config/.eslintrc')) + \ 'command': (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) + \ . ' -c ' . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/subdir-with-config/.eslintrc')) \ . ' --fix %t', \ }, \ ale#fixers#eslint#Fix(bufnr('')) @@ -37,9 +36,9 @@ Execute(package.json should be used as a last resort): AssertEqual \ { \ 'read_temporary_file': 1, - \ 'command': - \ ale#Escape(simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) - \ . ' -c ' . ale#Escape(simplify(g:dir . '/../eslint-test-files/react-app/.eslintrc.js')) + \ 'command': (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) + \ . ' -c ' . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/.eslintrc.js')) \ . ' --fix %t', \ }, \ ale#fixers#eslint#Fix(bufnr('')) @@ -50,8 +49,8 @@ Execute(package.json should be used as a last resort): \ { \ 'read_temporary_file': 1, \ 'command': - \ ale#Escape(simplify(g:dir . '/../eslint-test-files/node_modules/.bin/eslint')) - \ . ' -c ' . ale#Escape(simplify(g:dir . '/../eslint-test-files/package.json')) + \ ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/node_modules/.bin/eslint')) + \ . ' -c ' . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/package.json')) \ . ' --fix %t', \ }, \ ale#fixers#eslint#Fix(bufnr('')) diff --git a/test/fixers/test_isort_fixer_callback.vader b/test/fixers/test_isort_fixer_callback.vader index 437e276..ea4426d 100644 --- a/test/fixers/test_isort_fixer_callback.vader +++ b/test/fixers/test_isort_fixer_callback.vader @@ -9,9 +9,13 @@ Before: silent cd command_callback let g:dir = getcwd() + let b:bin_dir = has('win32') ? 'Scripts' : 'bin' + After: Restore + unlet! b:bin_dir + call ale#test#RestoreDirectory() Execute(The isort callback should return the correct default values): @@ -21,5 +25,5 @@ Execute(The isort callback should return the correct default values): silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py') AssertEqual - \ {'command': "'" . g:dir . "/python_paths/with_virtualenv/env/bin/isort' -" }, + \ {'command': ale#Escape(ale#path#Winify(g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/isort')) . ' -' }, \ ale#fixers#isort#Fix(bufnr('')) diff --git a/test/fixers/test_phpcbf_fixer_callback.vader b/test/fixers/test_phpcbf_fixer_callback.vader index c2fe3a6..cf02a0b 100644 --- a/test/fixers/test_phpcbf_fixer_callback.vader +++ b/test/fixers/test_phpcbf_fixer_callback.vader @@ -21,7 +21,7 @@ Execute(project with phpcbf should use local by default): call ale#test#SetFilename('php_paths/project-with-phpcbf/foo/test.php') AssertEqual - \ g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf', + \ ale#path#Winify(g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf'), \ ale#fixers#phpcbf#GetExecutable(bufnr('')) Execute(use-global should override local detection): @@ -43,7 +43,7 @@ Execute(The phpcbf callback should return the correct default values): call ale#test#SetFilename('php_paths/project-with-phpcbf/foo/test.php') AssertEqual - \ {'command': ale#Escape(g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf') . ' --stdin-path=%s ' }, + \ {'command': ale#Escape(ale#path#Winify(g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf')) . ' --stdin-path=%s ' }, \ ale#fixers#phpcbf#Fix(bufnr('')) Execute(The phpcbf callback should include the phpcbf_standard option): @@ -51,6 +51,62 @@ Execute(The phpcbf callback should include the phpcbf_standard option): call ale#test#SetFilename('php_paths/project-with-phpcbf/foo/test.php') AssertEqual - \ {'command': ale#Escape(g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf') . ' --stdin-path=%s ' . '--standard=phpcbf_ruleset.xml'}, + \ {'command': ale#Escape(ale#path#Winify(g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf')) . ' --stdin-path=%s ' . '--standard=phpcbf_ruleset.xml'}, + \ ale#fixers#phpcbf#Fix(bufnr('')) + +Before: + Save g:ale_php_phpcbf_executable + Save g:ale_php_phpcbf_standard + Save g:ale_php_phpcbf_use_global + + let g:ale_php_phpcbf_executable = 'phpcbf_test' + let g:ale_php_phpcbf_standard = '' + let g:ale_php_phpcbf_use_global = 0 + + call ale#test#SetDirectory('/testplugin/test/fixers') + silent cd .. + silent cd command_callback + let g:dir = getcwd() + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(project with phpcbf should use local by default): + call ale#test#SetFilename('php_paths/project-with-phpcbf/foo/test.php') + + AssertEqual + \ ale#path#Winify(g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf'), + \ ale#fixers#phpcbf#GetExecutable(bufnr('')) + +Execute(use-global should override local detection): + let g:ale_php_phpcbf_use_global = 1 + call ale#test#SetFilename('php_paths/project-with-phpcbf/foo/test.php') + + AssertEqual + \ 'phpcbf_test', + \ ale#fixers#phpcbf#GetExecutable(bufnr('')) + +Execute(project without phpcbf should use global): + call ale#test#SetFilename('php_paths/project-without-phpcbf/foo/test.php') + + AssertEqual + \ 'phpcbf_test', + \ ale#fixers#phpcbf#GetExecutable(bufnr('')) + +Execute(The phpcbf callback should return the correct default values): + call ale#test#SetFilename('php_paths/project-with-phpcbf/foo/test.php') + + AssertEqual + \ {'command': ale#Escape(ale#path#Winify(g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf')) . ' --stdin-path=%s ' }, + \ ale#fixers#phpcbf#Fix(bufnr('')) + +Execute(The phpcbf callback should include the phpcbf_standard option): + let g:ale_php_phpcbf_standard = 'phpcbf_ruleset.xml' + call ale#test#SetFilename('php_paths/project-with-phpcbf/foo/test.php') + + AssertEqual + \ {'command': ale#Escape(ale#path#Winify(g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf')) . ' --stdin-path=%s ' . '--standard=phpcbf_ruleset.xml'}, \ ale#fixers#phpcbf#Fix(bufnr('')) diff --git a/test/fixers/test_prettier_eslint_fixer.callback.vader b/test/fixers/test_prettier_eslint_fixer.callback.vader index 56daf93..b48a708 100644 --- a/test/fixers/test_prettier_eslint_fixer.callback.vader +++ b/test/fixers/test_prettier_eslint_fixer.callback.vader @@ -56,7 +56,7 @@ Execute(Configuration files should be detected): \ 'command': \ ale#Escape('prettier-eslint') \ . ' %t' - \ . ' --eslint-config-path ' . ale#Escape(g:dir . '/eslint-test-files/react-app/.eslintrc.js') + \ . ' --eslint-config-path ' . ale#Escape(ale#path#Winify(g:dir . '/eslint-test-files/react-app/.eslintrc.js')) \ . ' --write' \ }, \ ale#fixers#prettier_eslint#Fix(bufnr('')) diff --git a/test/fixers/test_prettier_fixer_callback.vader b/test/fixers/test_prettier_fixer_callback.vader index a684ad0..cc7d34d 100644 --- a/test/fixers/test_prettier_fixer_callback.vader +++ b/test/fixers/test_prettier_fixer_callback.vader @@ -39,7 +39,7 @@ Execute(The prettier callback should include configuration files when the option \ 'command': ale#Escape(g:ale_javascript_prettier_executable) \ . ' %t' \ . ' --parser babylon' - \ . ' --config ' . ale#Escape(simplify(g:dir . '/../prettier-test-files/with_config/.prettierrc')) + \ . ' --config ' . ale#Escape(ale#path#Winify(g:dir . '/../prettier-test-files/with_config/.prettierrc')) \ . ' --write', \ }, \ ale#fixers#prettier#Fix(bufnr('')) @@ -54,7 +54,7 @@ Execute(The prettier callback should include custom prettier options): \ 'command': ale#Escape(g:ale_javascript_prettier_executable) \ . ' %t' \ . ' --no-semi --parser babylon' - \ . ' --config ' . ale#Escape(simplify(g:dir . '/../prettier-test-files/with_config/.prettierrc')) + \ . ' --config ' . ale#Escape(ale#path#Winify(g:dir . '/../prettier-test-files/with_config/.prettierrc')) \ . ' --write', \ }, \ ale#fixers#prettier#Fix(bufnr('')) diff --git a/test/fixers/test_puppetlint_fixer_callback.vader b/test/fixers/test_puppetlint_fixer_callback.vader index 04a85e5..224d72a 100644 --- a/test/fixers/test_puppetlint_fixer_callback.vader +++ b/test/fixers/test_puppetlint_fixer_callback.vader @@ -21,7 +21,7 @@ Execute(The puppetlint callback should return the correct default values): AssertEqual \ {'read_temporary_file': 1, - \ 'command': "'" . g:ale_puppet_puppetlint_executable . "'" + \ 'command': ale#Escape(g:ale_puppet_puppetlint_executable) \ . ' ' . g:ale_puppet_puppetlint_options \ . ' --fix %t' }, \ ale#fixers#puppetlint#Fix(bufnr('')) diff --git a/test/fixers/test_rubocop_fixer_callback.vader b/test/fixers/test_rubocop_fixer_callback.vader index 87d56d0..ff2ca96 100644 --- a/test/fixers/test_rubocop_fixer_callback.vader +++ b/test/fixers/test_rubocop_fixer_callback.vader @@ -34,7 +34,7 @@ Execute(The rubocop callback should include configuration files): \ { \ 'read_temporary_file': 1, \ 'command': ale#Escape(g:ale_ruby_rubocop_executable) - \ . ' --config ' . ale#Escape(g:dir . '/ruby_paths/with_config/.rubocop.yml') + \ . ' --config ' . ale#Escape(ale#path#Winify(g:dir . '/ruby_paths/with_config/.rubocop.yml')) \ . ' --auto-correct %t', \ }, \ ale#fixers#rubocop#Fix(bufnr('')) @@ -47,7 +47,7 @@ Execute(The rubocop callback should include custom rubocop options): \ { \ 'read_temporary_file': 1, \ 'command': ale#Escape(g:ale_ruby_rubocop_executable) - \ . ' --config ' . ale#Escape(g:dir . '/ruby_paths/with_config/.rubocop.yml') + \ . ' --config ' . ale#Escape(ale#path#Winify(g:dir . '/ruby_paths/with_config/.rubocop.yml')) \ . ' --except Lint/Debugger' \ . ' --auto-correct %t', \ }, diff --git a/test/fixers/test_standard_fixer_callback.vader b/test/fixers/test_standard_fixer_callback.vader index 88169bb..34c752d 100644 --- a/test/fixers/test_standard_fixer_callback.vader +++ b/test/fixers/test_standard_fixer_callback.vader @@ -2,31 +2,16 @@ Before: call ale#test#SetDirectory('/testplugin/test/fixers') After: - let g:ale_has_override = {} call ale#test#RestoreDirectory() -Execute(The path to standard.js should be run on Unix): +Execute(The executable path should be correct): call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') AssertEqual \ { \ 'read_temporary_file': 1, - \ 'command': - \ ale#Escape(simplify(g:dir . '/../eslint-test-files/react-app/node_modules/standard/bin/cmd.js')) - \ . ' --fix %t', - \ }, - \ ale#fixers#standard#Fix(bufnr('')) - -Execute(The standard fixer with standard.js should be run with node on Windows): - call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') - let g:ale_has_override['win32'] = 1 - - " We have to execute the file with node. - AssertEqual - \ { - \ 'read_temporary_file': 1, - \ 'command': ale#Escape('node.exe') . ' ' - \ . ale#Escape(simplify(g:dir . '/../eslint-test-files/react-app/node_modules/standard/bin/cmd.js')) + \ 'command': (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/node_modules/standard/bin/cmd.js')) \ . ' --fix %t', \ }, \ ale#fixers#standard#Fix(bufnr('')) diff --git a/test/fixers/test_stylelint_fixer_callback.vader b/test/fixers/test_stylelint_fixer_callback.vader index 482704d..a0fc6ff 100644 --- a/test/fixers/test_stylelint_fixer_callback.vader +++ b/test/fixers/test_stylelint_fixer_callback.vader @@ -2,31 +2,16 @@ Before: call ale#test#SetDirectory('/testplugin/test/fixers') After: - let g:ale_has_override = {} call ale#test#RestoreDirectory() -Execute(The path to stylelint.js should be run on Unix): +Execute(The executable path should be correct): call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.css') AssertEqual \ { \ 'read_temporary_file': 1, - \ 'command': - \ ale#Escape(simplify(g:dir . '/../eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js')) - \ . ' --fix %t', - \ }, - \ ale#fixers#stylelint#Fix(bufnr('')) - -Execute(The stylelint fixer with stylelint.js should be run with node on Windows): - call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.css') - let g:ale_has_override['win32'] = 1 - - " We have to execute the file with node. - AssertEqual - \ { - \ 'read_temporary_file': 1, - \ 'command': ale#Escape('node.exe') . ' ' - \ . ale#Escape(simplify(g:dir . '/../eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js')) + \ 'command': (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Winify(g:dir . '/../eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js')) \ . ' --fix %t', \ }, \ ale#fixers#stylelint#Fix(bufnr(''))