]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/fixers/prettier_eslint.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / fixers / prettier_eslint.vim
1 " Author: tunnckoCore (Charlike Mike Reagent) <mameto2011@gmail.com>,
2 "         w0rp <devw0rp@gmail.com>, morhetz (Pavel Pertsev) <morhetz@gmail.com>
3 " Description: Integration between Prettier and ESLint.
4
5 call ale#Set('javascript_prettier_eslint_executable', 'prettier-eslint')
6 call ale#Set('javascript_prettier_eslint_use_global', get(g:, 'ale_use_global_executables', 0))
7 call ale#Set('javascript_prettier_eslint_options', '')
8
9 function! ale#fixers#prettier_eslint#GetExecutable(buffer) abort
10     return ale#path#FindExecutable(a:buffer, 'javascript_prettier_eslint', [
11     \   'node_modules/prettier-eslint-cli/dist/index.js',
12     \   'node_modules/.bin/prettier-eslint',
13     \])
14 endfunction
15
16 function! ale#fixers#prettier_eslint#Fix(buffer) abort
17     return ale#semver#RunWithVersionCheck(
18     \   a:buffer,
19     \   ale#fixers#prettier_eslint#GetExecutable(a:buffer),
20     \   '%e --version',
21     \   function('ale#fixers#prettier_eslint#ApplyFixForVersion'),
22     \)
23 endfunction
24
25 function! ale#fixers#prettier_eslint#ApplyFixForVersion(buffer, version) abort
26     let l:options = ale#Var(a:buffer, 'javascript_prettier_eslint_options')
27     let l:executable = ale#fixers#prettier_eslint#GetExecutable(a:buffer)
28
29     " 4.2.0 is the first version with --eslint-config-path
30     let l:config = ale#semver#GTE(a:version, [4, 2, 0])
31     \   ? ale#handlers#eslint#FindConfig(a:buffer)
32     \   : ''
33     let l:eslint_config_option = !empty(l:config)
34     \   ? ' --eslint-config-path ' . ale#Escape(l:config)
35     \   : ''
36
37     " 4.4.0 is the first version with --stdin-filepath
38     if ale#semver#GTE(a:version, [4, 4, 0])
39         return {
40         \   'cwd': '%s:h',
41         \   'command': ale#Escape(l:executable)
42         \       . l:eslint_config_option
43         \       . (!empty(l:options) ? ' ' . l:options : '')
44         \       . ' --stdin-filepath %s --stdin',
45         \}
46     endif
47
48     return {
49     \   'command': ale#Escape(l:executable)
50     \       . ' %t'
51     \       . l:eslint_config_option
52     \       . (!empty(l:options) ? ' ' . l:options : '')
53     \       . ' --write',
54     \   'read_temporary_file': 1,
55     \}
56 endfunction