summaryrefslogtreecommitdiff
path: root/ale_linters/javascript
diff options
context:
space:
mode:
authorZach Perrault <zach.perrault@gmail.com>2016-11-01 04:00:08 -0500
committerw0rp <w0rp@users.noreply.github.com>2016-11-01 09:00:08 +0000
commit4088347901ad5f0388d65b347501223abb2aa475 (patch)
tree15047b3296e3f4da0291f8e21a9da6a1071f96d2 /ale_linters/javascript
parent614a30a508bc324b9349cd1814964fb93146bee8 (diff)
downloadale-4088347901ad5f0388d65b347501223abb2aa475.zip
Add FlowType support (#157)
* Add `javascript/flow` linter * Add documentation for flow * Remove a line from the docs that was from eslint * Only run if flow gives output; Correct link in doc * Address PR feedback #157
Diffstat (limited to 'ale_linters/javascript')
-rw-r--r--ale_linters/javascript/flow.vim66
1 files changed, 66 insertions, 0 deletions
diff --git a/ale_linters/javascript/flow.vim b/ale_linters/javascript/flow.vim
new file mode 100644
index 00000000..0a07c192
--- /dev/null
+++ b/ale_linters/javascript/flow.vim
@@ -0,0 +1,66 @@
+" Author: Zach Perrault -- @zperrault
+" Description: FlowType checking for JavaScript files
+
+let g:ale_javascript_flow_executable =
+\ get(g:, 'ale_javascript_flow_executable', 'flow')
+
+let g:ale_javascript_flow_use_global =
+\ get(g:, 'ale_javascript_flow_use_global', 0)
+
+function! ale_linters#javascript#flow#GetExecutable(buffer) abort
+ if g:ale_javascript_flow_use_global
+ return g:ale_javascript_flow_executable
+ endif
+
+ return ale#util#ResolveLocalPath(
+ \ a:buffer,
+ \ 'node_modules/.bin/flow',
+ \ g:ale_javascript_flow_executable
+ \)
+endfunction
+
+function! ale_linters#javascript#flow#GetCommand(buffer) abort
+ return ale_linters#javascript#flow#GetExecutable(a:buffer)
+ \ . ' check-contents --json --from ale'
+endfunction
+
+function! ale_linters#javascript#flow#Handle(buffer, lines)
+ let l:flow_output = json_decode(join(a:lines, ''))
+
+ if has_key(l:flow_output, 'errors')
+ let l:output = []
+
+ for l:error in l:flow_output.errors
+ " Each error is broken up into parts
+ let l:text = ''
+ let l:line = 0
+ for l:message in l:error.message
+ " Comments have no line of column information
+ if l:message.line + 0
+ let l:line = l:message.line + 0
+ endif
+ let l:text = l:text . ' ' . l:message.descr
+ endfor
+
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:line,
+ \ 'vcol': 0,
+ \ 'col': 0,
+ \ 'text': l:text,
+ \ 'type': l:error.level ==# 'error' ? 'E' : 'W',
+ \})
+ endfor
+
+ return l:output
+ else
+ return []
+ endif
+endfunction
+
+call ale#linter#Define('javascript', {
+\ 'name': 'flow',
+\ 'executable_callback': 'ale_linters#javascript#flow#GetExecutable',
+\ 'command_callback': 'ale_linters#javascript#flow#GetCommand',
+\ 'callback': 'ale_linters#javascript#flow#Handle',
+\})