]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/handlers/alex.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 / handlers / alex.vim
1 scriptencoding utf-8
2 " Author: Johannes Wienke <languitar@semipol.de>
3 " Description: Error handling for errors in alex output format
4
5 function! ale#handlers#alex#GetExecutable(buffer) abort
6     return ale#path#FindExecutable(a:buffer, 'alex', [
7     \   'node_modules/.bin/alex',
8     \   'node_modules/alex/cli.js',
9     \])
10 endfunction
11
12 function! ale#handlers#alex#CreateCommandCallback(flags) abort
13     return {b -> ale#node#Executable(b, ale#handlers#alex#GetExecutable(b))
14     \            . ' --stdin '
15     \            . a:flags
16     \}
17 endfunction
18
19 function! ale#handlers#alex#Handle(buffer, lines) abort
20     " Example output:
21     "       6:256-6:262  warning  Be careful with “killed”, it’s profane in some cases      killed           retext-profanities
22     let l:pattern = '\v^ *(\d+):(\d+)-(\d+):(\d+) +warning +(.{-})  +(.{-})  +(.{-})$'
23     let l:output = []
24
25     for l:match in ale#util#GetMatches(a:lines, l:pattern)
26         call add(l:output, {
27         \   'lnum': l:match[1] + 0,
28         \   'col': l:match[2] + 0,
29         \   'end_lnum': l:match[3] + 0,
30         \   'end_col': l:match[4] - 1,
31         \   'text': l:match[5] . ' (' . (l:match[7]) . ')',
32         \   'type': 'W',
33         \})
34     endfor
35
36     return l:output
37 endfunction
38
39 " Define a linter for a specific filetype. Accept flags to adapt to the filetype.
40 "    no flags  treat input as markdown
41 "    --html    treat input as HTML
42 "    --mdx     treat input as MDX
43 "    --text    treat input as plaintext
44 function! ale#handlers#alex#DefineLinter(filetype, flags) abort
45     call ale#Set('alex_executable', 'alex')
46     call ale#Set('alex_use_global', get(g:, 'ale_use_global_executables', 0))
47
48     call ale#linter#Define(a:filetype, {
49     \   'name': 'alex',
50     \   'executable': function('ale#handlers#alex#GetExecutable'),
51     \   'command': ale#handlers#alex#CreateCommandCallback(a:flags),
52     \   'output_stream': 'stderr',
53     \   'callback': 'ale#handlers#alex#Handle',
54     \})
55 endfunction