summaryrefslogtreecommitdiff
path: root/ale_linters/c
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2016-09-18 19:33:33 +0100
committerw0rp <devw0rp@gmail.com>2016-09-18 19:33:33 +0100
commitb66b6f925acaa6e44a4110dc3b269630045462e2 (patch)
tree10a7382d680079095b145bcb877c65226bf9a64f /ale_linters/c
parent9553c24fa00ac8499d01adbb55d32403f180bf53 (diff)
downloadale-b66b6f925acaa6e44a4110dc3b269630045462e2.zip
Add support for checking C code with GCC too.
Diffstat (limited to 'ale_linters/c')
-rw-r--r--ale_linters/c/gcc.vim49
1 files changed, 49 insertions, 0 deletions
diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim
new file mode 100644
index 00000000..6bd335d8
--- /dev/null
+++ b/ale_linters/c/gcc.vim
@@ -0,0 +1,49 @@
+if exists('g:loaded_ale_linters_c_gcc')
+ finish
+endif
+
+let g:loaded_ale_linters_c_gcc = 1
+
+" Set this option to change the GCC options for warnings for C.
+if !exists('g:ale_c_gcc_options')
+ let g:ale_c_gcc_options = '-Wall'
+endif
+
+function! ale_linters#c#gcc#Handle(buffer, lines)
+ " Look for lines like the following.
+ "
+ " <stdin>:8:5: warning: conversion lacks type at end of format [-Wformat=]
+ " <stdin>:10:27: error: invalid operands to binary - (have ‘int’ and ‘char *’)
+ let pattern = '^<stdin>:\(\d\+\):\(\d\+\): \(warning\|error\): \(.\+\)$'
+ let output = []
+
+ for line in a:lines
+ let l:match = matchlist(line, pattern)
+
+ if len(l:match) == 0
+ continue
+ endif
+
+ call add(output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:match[1] + 0,
+ \ 'vcol': 0,
+ \ 'col': l:match[2] + 0,
+ \ 'text': l:match[4],
+ \ 'type': l:match[3] ==# 'warning' ? 'W' : 'E',
+ \ 'nr': -1,
+ \})
+ endfor
+
+ return output
+endfunction
+
+call ALEAddLinter('c', {
+\ 'name': 'gcc',
+\ 'output_stream': 'stderr',
+\ 'executable': 'gcc',
+\ 'command': 'gcc -S -x c -fsyntax-only '
+\ . g:ale_c_gcc_options
+\ . ' -',
+\ 'callback': 'ale_linters#c#gcc#Handle',
+\})