]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/javascript/jscs.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:

Merge commit '294584081929424aec883f90c7d6515b3743358d' as '.vim/bundle/vim-lsp-ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / javascript / jscs.vim
1 " Author: Chris Kyrouac - https://github.com/fijshion
2 " Description: jscs for JavaScript files
3
4 call ale#Set('javascript_jscs_executable', 'jscs')
5 call ale#Set('javascript_jscs_use_global', get(g:, 'ale_use_global_executables', 0))
6
7 function! ale_linters#javascript#jscs#GetCommand(buffer) abort
8     " Search for a local JShint config locaation, and default to a global one.
9     let l:jscs_config = ale#path#ResolveLocalPath(
10     \   a:buffer,
11     \   '.jscsrc',
12     \   get(g:, 'ale_jscs_config_loc', '')
13     \)
14
15     let l:command = '%e --reporter inline --no-colors'
16
17     if !empty(l:jscs_config)
18         let l:command .= ' --config ' . ale#Escape(l:jscs_config)
19     endif
20
21     let l:command .= ' -'
22
23     return l:command
24 endfunction
25
26 function! ale_linters#javascript#jscs#Handle(buffer, lines) abort
27     " Matches patterns looking like the following
28     "
29     " foobar.js: line 2, col 1, Expected indentation of 1 characters
30     "
31     let l:pattern = '\v^.*:\s+line (\d+),\s+col\s+(\d+),\s+(.*)$'
32     let l:output = []
33
34     for l:match in ale#util#GetMatches(a:lines, l:pattern)
35         let l:obj = {
36         \   'lnum': l:match[1] + 0,
37         \   'col': l:match[2] + 0,
38         \   'text': l:match[3]
39         \}
40
41         let l:code_match = matchlist(l:match[3], '\v([^ :]+): (.+)$')
42
43         if !empty(l:code_match)
44             let l:obj.code = l:code_match[1]
45             let l:obj.text = l:code_match[2]
46         endif
47
48         call add(l:output, l:obj)
49     endfor
50
51     return l:output
52 endfunction
53
54 call ale#linter#Define('javascript', {
55 \   'name': 'jscs',
56 \   'executable': {b -> ale#path#FindExecutable(b, 'javascript_jscs', [
57 \       'node_modules/.bin/jscs',
58 \   ])},
59 \   'command': function('ale_linters#javascript#jscs#GetCommand'),
60 \   'callback': 'ale_linters#javascript#jscs#Handle',
61 \})