]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/scala/scalastyle.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 '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / scala / scalastyle.vim
1 " Author: Kevin Kays - https://github.com/okkays
2 " Description: Support for the scalastyle checker.
3
4 call ale#Set('scala_scalastyle_options', '')
5 " TODO: Remove support for the old option name in ALE 3.0.
6 call ale#Set('scala_scalastyle_config',
7 \   get(g:, 'ale_scalastyle_config_loc', '')
8 \)
9
10 function! ale_linters#scala#scalastyle#Handle(buffer, lines) abort
11     " Look for help output from scalastyle first, which indicates that no
12     " configuration file was found.
13     for l:line in a:lines[:10]
14         if l:line =~# '-c, --config'
15             return [{
16             \   'lnum': 1,
17             \   'text': '(See :help ale-scala-scalastyle)'
18             \       . ' No scalastyle configuration file was found.',
19             \}]
20         endif
21     endfor
22
23     " Matches patterns like the following:
24     "
25     " warning file=/home/blurble/Doop.scala message=Missing or badly formed ScalaDoc: Extra @param foobles line=190
26     let l:patterns = [
27     \   '^\(.\+\) .\+ message=\(.\+\) line=\(\d\+\)$',
28     \   '^\(.\+\) .\+ message=\(.\+\) line=\(\d\+\) column=\(\d\+\)$',
29     \]
30     let l:output = []
31
32     for l:match in ale#util#GetMatches(a:lines, l:patterns)
33         let l:args = {
34         \   'lnum': l:match[3] + 0,
35         \   'type': l:match[1] =~? 'error' ? 'E' : 'W',
36         \   'text': l:match[2]
37         \}
38
39         if !empty(l:match[4])
40             let l:args['col'] = l:match[4] + 1
41         endif
42
43         call add(l:output, l:args)
44     endfor
45
46     return l:output
47 endfunction
48
49 function! ale_linters#scala#scalastyle#GetCommand(buffer) abort
50     " Search for scalastyle config in parent directories.
51     let l:scalastyle_config = ''
52     let l:potential_configs = [
53     \   'scalastyle_config.xml',
54     \   'scalastyle-config.xml'
55     \]
56
57     for l:config in l:potential_configs
58         let l:scalastyle_config = ale#path#ResolveLocalPath(
59         \   a:buffer,
60         \   l:config,
61         \   ''
62         \)
63
64         if !empty(l:scalastyle_config)
65             break
66         endif
67     endfor
68
69     " If all else fails, try the global config.
70     if empty(l:scalastyle_config)
71         let l:scalastyle_config = ale#Var(a:buffer, 'scala_scalastyle_config')
72     endif
73
74     return 'scalastyle'
75     \ . (!empty(l:scalastyle_config) ? ' --config ' . ale#Escape(l:scalastyle_config) : '')
76     \ . ale#Pad(ale#Var(a:buffer, 'scala_scalastyle_options'))
77     \ . ' %t'
78 endfunction
79
80 call ale#linter#Define('scala', {
81 \   'name': 'scalastyle',
82 \   'executable': 'scalastyle',
83 \   'output_stream': 'stdout',
84 \   'command': function('ale_linters#scala#scalastyle#GetCommand'),
85 \   'callback': 'ale_linters#scala#scalastyle#Handle',
86 \})