summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/javascript/jshint.vim34
-rw-r--r--ale_linters/markdown/mdl.vim35
-rw-r--r--ale_linters/matlab/mlint.vim55
3 files changed, 114 insertions, 10 deletions
diff --git a/ale_linters/javascript/jshint.vim b/ale_linters/javascript/jshint.vim
index 327158a8..f82011dd 100644
--- a/ale_linters/javascript/jshint.vim
+++ b/ale_linters/javascript/jshint.vim
@@ -4,17 +4,31 @@
let g:ale_javascript_jshint_executable =
\ get(g:, 'ale_javascript_jshint_executable', 'jshint')
-function! ale_linters#javascript#jshint#GetCommand(buffer)
- " Set this to the location of the jshint configuration file to
- " use a fixed location for .jshintrc
- if exists('g:ale_jshint_config_loc')
- let l:jshint_config = g:ale_jshint_config_loc
- else
- " Look for the JSHint config in parent directories.
- let l:jshint_config = ale#util#FindNearestFile(a:buffer, '.jshintrc')
+let g:ale_javascript_jshint_use_global =
+\ get(g:, 'ale_javascript_jshint_use_global', 0)
+
+function! ale_linters#javascript#jshint#GetExecutable(buffer) abort
+ if g:ale_javascript_jshint_use_global
+ return g:ale_javascript_jshint_executable
endif
- let l:command = g:ale_javascript_jshint_executable . ' --reporter unix'
+ return ale#util#ResolveLocalPath(
+ \ a:buffer,
+ \ 'node_modules/.bin/jshint',
+ \ g:ale_javascript_jshint_executable
+ \)
+endfunction
+
+function! ale_linters#javascript#jshint#GetCommand(buffer)
+ " Search for a local JShint config locaation, and default to a global one.
+ let l:jshint_config = ale#util#ResolveLocalPath(
+ \ a:buffer,
+ \ '.jshintrc',
+ \ get(g:, 'ale_jshint_config_loc', '')
+ \)
+
+ let l:command = ale_linters#javascript#jshint#GetExecutable(a:buffer)
+ let l:command .= ' --reporter unix'
if !empty(l:jshint_config)
let l:command .= ' --config ' . fnameescape(l:jshint_config)
@@ -27,7 +41,7 @@ endfunction
call ale#linter#Define('javascript', {
\ 'name': 'jshint',
-\ 'executable': g:ale_javascript_jshint_executable,
+\ 'executable_callback': 'ale_linters#javascript#jshint#GetExecutable',
\ 'command_callback': 'ale_linters#javascript#jshint#GetCommand',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\})
diff --git a/ale_linters/markdown/mdl.vim b/ale_linters/markdown/mdl.vim
new file mode 100644
index 00000000..c984252e
--- /dev/null
+++ b/ale_linters/markdown/mdl.vim
@@ -0,0 +1,35 @@
+" Author: Steve Dignam <steve@dignam.xyz>
+" Description: Support for mdl, a markdown linter
+
+function! ale_linters#markdown#mdl#Handle(buffer, lines) abort
+ " matches: '(stdin):173: MD004 Unordered list style'
+ let l:pattern = ':\(\d*\): \(.*\)$'
+ let l:output = []
+
+ for l:line in a:lines
+ let l:match = matchlist(l:line, l:pattern)
+
+ if len(l:match) == 0
+ continue
+ endif
+
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:match[1] + 0,
+ \ 'vcol': 0,
+ \ 'col': 0,
+ \ 'text': l:match[2],
+ \ 'type': 'W',
+ \ 'nr': -1,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('markdown', {
+\ 'name': 'mdl',
+\ 'executable': 'mdl',
+\ 'command': 'mdl',
+\ 'callback': 'ale_linters#markdown#mdl#Handle'
+\})
diff --git a/ale_linters/matlab/mlint.vim b/ale_linters/matlab/mlint.vim
new file mode 100644
index 00000000..e1e6cf05
--- /dev/null
+++ b/ale_linters/matlab/mlint.vim
@@ -0,0 +1,55 @@
+" Author: awlayton <alex@layton.in>
+" Description: mlint for MATLAB files
+
+let g:ale_matlab_mlint_executable =
+\ get(g:, 'ale_matlab_mlint_executable', 'mlint')
+
+function! ale_linters#matlab#mlint#Handle(buffer, lines)
+ " Matches patterns like the following:
+ "
+ " L 27 (C 1): FNDEF: Terminate statement with semicolon to suppress output.
+ " L 30 (C 13-15): FNDEF: A quoted string is unterminated.
+ let l:pattern = '^L \(\d\+\) (C \([0-9-]\+\)): \([A-Z]\+\): \(.\+\)$'
+ let l:output = []
+
+ for l:line in a:lines
+ let l:match = matchlist(l:line, l:pattern)
+
+ if len(l:match) == 0
+ continue
+ endif
+
+ let l:lnum = l:match[1] + 0
+ let l:col = l:match[2] + 0
+ let l:code = l:match[3]
+ let l:text = l:match[4]
+
+ " Suppress erroneous waring about filename
+ " TODO: Enable this error when copying filename is supported
+ if l:code ==# 'FNDEF'
+ continue
+ endif
+
+ " vcol is needed to indicate that the column is a character.
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:lnum,
+ \ 'vcol': 0,
+ \ 'col': l:col,
+ \ 'text': l:text,
+ \ 'type': 'W',
+ \ 'nr': -1,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('matlab', {
+\ 'name': 'mlint',
+\ 'executable': 'mlint',
+\ 'command': g:ale#util#stdin_wrapper .
+\ ' .m ' . g:ale_matlab_mlint_executable . ' -id',
+\ 'output_stream': 'stderr',
+\ 'callback': 'ale_linters#matlab#mlint#Handle',
+\})