summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--ale_linters/c/cppcheck.vim17
-rw-r--r--ale_linters/cpp/clangtidy.vim21
-rw-r--r--ale_linters/cpp/cppcheck.vim17
-rw-r--r--ale_linters/kotlin/kotlinc.vim116
-rw-r--r--doc/ale-cpp.txt27
-rw-r--r--doc/ale-kotlin.txt65
-rw-r--r--doc/ale.txt3
-rw-r--r--test/command_callback/cppcheck_paths/one/compile_commands.json0
-rw-r--r--test/command_callback/cppcheck_paths/one/two/three/file.c0
-rw-r--r--test/command_callback/cppcheck_paths/one/two/three/file.cpp0
-rw-r--r--test/command_callback/test_clang_tidy_command_callback.vader31
-rw-r--r--test/command_callback/test_cppcheck_command_callbacks.vader40
13 files changed, 330 insertions, 8 deletions
diff --git a/README.md b/README.md
index 55b716a6..a09924e5 100644
--- a/README.md
+++ b/README.md
@@ -81,6 +81,7 @@ name. That seems to be the fairest way to arrange this table.
| Java | [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html) |
| JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [flow](https://flowtype.org/), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo)
| JSON | [jsonlint](http://zaa.ch/jsonlint/) |
+| Kotlin | [kotlinc](https://kotlinlang.org) see `:help ale-integration-kotlin` for configuration instructions
| LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck) |
| Lua | [luacheck](https://github.com/mpeterv/luacheck) |
| Markdown | [mdl](https://github.com/mivok/markdownlint), [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) |
diff --git a/ale_linters/c/cppcheck.vim b/ale_linters/c/cppcheck.vim
index 7da5b3ab..90805914 100644
--- a/ale_linters/c/cppcheck.vim
+++ b/ale_linters/c/cppcheck.vim
@@ -5,7 +5,22 @@
let g:ale_c_cppcheck_options = get(g:, 'ale_c_cppcheck_options', '--enable=style')
function! ale_linters#c#cppcheck#GetCommand(buffer) abort
- return 'cppcheck -q --language=c '
+ " Search upwards from the file for compile_commands.json.
+ "
+ " If we find it, we'll `cd` to where the compile_commands.json file is,
+ " then use the file to set up import paths, etc.
+ let l:compile_commmands_path = ale#path#FindNearestFile(a:buffer, 'compile_commands.json')
+
+ let l:cd_command = !empty(l:compile_commmands_path)
+ \ ? ale#path#CdString(fnamemodify(l:compile_commmands_path, ':h'))
+ \ : ''
+ let l:compile_commands_option = !empty(l:compile_commmands_path)
+ \ ? '--project=compile_commands.json '
+ \ : ''
+
+ return l:cd_command
+ \ . 'cppcheck -q --language=c '
+ \ . l:compile_commands_option
\ . ale#Var(a:buffer, 'c_cppcheck_options')
\ . ' %t'
endfunction
diff --git a/ale_linters/cpp/clangtidy.vim b/ale_linters/cpp/clangtidy.vim
index 2acd345a..f538d14a 100644
--- a/ale_linters/cpp/clangtidy.vim
+++ b/ale_linters/cpp/clangtidy.vim
@@ -1,12 +1,24 @@
" Author: vdeurzen <tim@kompiler.org>, w0rp <devw0rp@gmail.com>
" Description: clang-tidy linter for cpp files
-" Set this option to change the clang-tidy options for warnings for C.
-let g:ale_cpp_clangtidy_options =
-\ get(g:, 'ale_cpp_clangtidy_options', '-std=c++14 -Wall')
+" Set this option to check the checks clang-tidy will apply.
+let g:ale_cpp_clangtidy_checks = get(g:, 'ale_cpp_clangtidy_checks', ['*'])
+
+" Set this option to manually set some options for clang-tidy.
+" This will disable compile_commands.json detection.
+let g:ale_cpp_clangtidy_options = get(g:, 'ale_cpp_clangtidy_options', '')
function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort
- return 'clang-tidy %t -- ' . ale#Var(a:buffer, 'cpp_clangtidy_options')
+ let l:check_list = ale#Var(a:buffer, 'cpp_clangtidy_checks')
+ let l:check_option = !empty(l:check_list)
+ \ ? '-checks=' . shellescape(join(l:check_list, ',')) . ' '
+ \ : ''
+ let l:user_options = ale#Var(a:buffer, 'cpp_clangtidy_options')
+ let l:extra_options = !empty(l:user_options)
+ \ ? ' -- ' . l:user_options
+ \ : ''
+
+ return 'clang-tidy ' . l:check_option . '%s' . l:extra_options
endfunction
call ale#linter#Define('cpp', {
@@ -15,4 +27,5 @@ call ale#linter#Define('cpp', {
\ 'executable': 'clang-tidy',
\ 'command_callback': 'ale_linters#cpp#clangtidy#GetCommand',
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
+\ 'lint_file': 1,
\})
diff --git a/ale_linters/cpp/cppcheck.vim b/ale_linters/cpp/cppcheck.vim
index 49cab0d9..2255f63f 100644
--- a/ale_linters/cpp/cppcheck.vim
+++ b/ale_linters/cpp/cppcheck.vim
@@ -5,7 +5,22 @@
let g:ale_cpp_cppcheck_options = get(g:, 'ale_cpp_cppcheck_options', '--enable=style')
function! ale_linters#cpp#cppcheck#GetCommand(buffer) abort
- return 'cppcheck -q --language=c++ '
+ " Search upwards from the file for compile_commands.json.
+ "
+ " If we find it, we'll `cd` to where the compile_commands.json file is,
+ " then use the file to set up import paths, etc.
+ let l:compile_commmands_path = ale#path#FindNearestFile(a:buffer, 'compile_commands.json')
+
+ let l:cd_command = !empty(l:compile_commmands_path)
+ \ ? ale#path#CdString(fnamemodify(l:compile_commmands_path, ':h'))
+ \ : ''
+ let l:compile_commands_option = !empty(l:compile_commmands_path)
+ \ ? '--project=compile_commands.json '
+ \ : ''
+
+ return l:cd_command
+ \ . 'cppcheck -q --language=c++ '
+ \ . l:compile_commands_option
\ . ale#Var(a:buffer, 'cpp_cppcheck_options')
\ . ' %t'
endfunction
diff --git a/ale_linters/kotlin/kotlinc.vim b/ale_linters/kotlin/kotlinc.vim
new file mode 100644
index 00000000..0ada361f
--- /dev/null
+++ b/ale_linters/kotlin/kotlinc.vim
@@ -0,0 +1,116 @@
+" Author: Francis Agyapong <francisgyapong2@gmail.com>
+" Description: A linter for the Kotlin programming language that uses kotlinc
+
+let g:ale_kotlin_kotlinc_options = get(g:, 'ale_kotlin_kotlinc_options', '')
+let g:ale_kotlin_kotlinc_enable_config = get(g:, 'ale_kotlin_kotlinc_enable_config', 0)
+let g:ale_kotlin_kotlinc_config_file = get(g:, 'ale_kotlin_kotlinc_config_file', '.ale_kotlinc_config')
+let g:ale_kotlin_kotlinc_classpath = get(g:, 'ale_kotlin_kotlinc_classpath', '')
+let g:ale_kotlin_kotlinc_sourcepath = get(g:, 'ale_kotlin_kotlinc_sourcepath', '')
+let g:ale_kotlin_kotlinc_use_module_file = get(g:, 'ale_kotlin_kotlinc_use_module_file', 0)
+let g:ale_kotlin_kotlinc_module_filename = get(g:, 'ale_kotlin_kotlinc_module_filename', 'module.xml')
+
+function! ale_linters#kotlin#kotlinc#GetCommand(buffer) abort
+ let l:kotlinc_opts = ale#Var(a:buffer, 'kotlin_kotlinc_options')
+ let l:command = 'kotlinc '
+
+ " If the config file is enabled and readable, source it
+ if ale#Var(a:buffer, 'kotlin_kotlinc_enable_config')
+ if filereadable(expand(ale#Var(a:buffer, 'kotlin_kotlinc_config_file'), 1))
+ execute 'source ' . fnameescape(expand(ale#Var(a:buffer, 'kotlin_kotlinc_config_file'), 1))
+ endif
+ endif
+
+ " If use module and module file is readable use that and return
+ if ale#Var(a:buffer, 'kotlin_kotlinc_use_module_file')
+ let l:module_filename = fnameescape(expand(ale#Var(a:buffer, 'kotlin_kotlinc_module_filename'), 1))
+
+ if filereadable(l:module_filename)
+ let l:kotlinc_opts .= ' -module ' . l:module_filename
+ let l:command .= 'kotlinc ' . l:kotlinc_opts
+
+ return l:command
+ endif
+ endif
+
+ " We only get here if not using module or the module file not readable
+ if ale#Var(a:buffer, 'kotlin_kotlinc_classpath') !=# ''
+ let l:kotlinc_opts .= ' -cp ' . ale#Var(a:buffer, 'kotlin_kotlinc_classpath')
+ endif
+
+ let l:fname = ''
+
+ if ale#Var(a:buffer, 'kotlin_kotlinc_sourcepath') !=# ''
+ let l:fname .= expand(ale#Var(a:buffer, 'kotlin_kotlinc_sourcepath'), 1) . ' '
+ endif
+ let l:fname .= shellescape(expand('#' . a:buffer . ':p'))
+ let l:command .= l:kotlinc_opts . ' ' . l:fname
+
+ return l:command
+endfunction
+
+function! ale_linters#kotlin#kotlinc#Handle(buffer, lines) abort
+ let l:code_pattern = '^\(.*\):\([0-9]\+\):\([0-9]\+\):\s\+\(error\|warning\):\s\+\(.*\)'
+ let l:general_pattern = '^\(warning\|error\|info\):\s*\(.*\)'
+ let l:output = []
+
+ for l:line in a:lines
+ let l:match = matchlist(l:line, l:code_pattern)
+
+ if len(l:match) == 0
+ continue
+ endif
+
+ let l:file = l:match[1]
+ let l:line = l:match[2] + 0
+ let l:column = l:match[3] + 0
+ let l:type = l:match[4]
+ let l:text = l:match[5]
+
+ let l:buf_abspath = fnamemodify(l:file, ':p')
+ let l:curbuf_abspath = expand('#' . a:buffer . ':p')
+
+ " Skip if file is not loaded
+ if l:buf_abspath !=# l:curbuf_abspath
+ continue
+ endif
+ let l:type_marker_str = l:type ==# 'warning' ? 'W' : 'E'
+
+ call add(l:output, {
+ \ 'lnum': l:line,
+ \ 'col': l:column,
+ \ 'text': l:text,
+ \ 'type': l:type_marker_str,
+ \})
+ endfor
+
+ " Non-code related messages
+ for l:line in a:lines
+ let l:match = matchlist(l:line, l:general_pattern)
+
+ if len(l:match) == 0
+ continue
+ endif
+
+ let l:type = l:match[1]
+ let l:text = l:match[2]
+
+ let l:type_marker_str = l:type ==# 'warning' || l:type ==# 'info' ? 'W' : 'E'
+
+ call add(l:output, {
+ \ 'lnum': -1,
+ \ 'text': l:text,
+ \ 'type': l:type_marker_str,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('kotlin', {
+\ 'name': 'kotlinc',
+\ 'output_stream': 'stderr',
+\ 'executable': 'kotlinc',
+\ 'command_callback': 'ale_linters#kotlin#kotlinc#GetCommand',
+\ 'callback': 'ale_linters#kotlin#kotlinc#Handle',
+\ 'lint_file': 1,
+\})
diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt
index 3baa767a..71673826 100644
--- a/doc/ale-cpp.txt
+++ b/doc/ale-cpp.txt
@@ -16,12 +16,35 @@ g:ale_cpp_clang_options *g:ale_cpp_clang_options*
-------------------------------------------------------------------------------
clangtidy *ale-cpp-clangtidy*
+`clang-tidy` will be run only when files are saved to disk, so that
+`compile_commands.json` files can be used. It is recommended to use this
+linter in combination with `compile_commands.json` files.
+
+
+g:ale_cpp_clangtidy_checks *g:ale_cpp_clangtidy_checks*
+ *b:ale_cpp_clangtidy_checks*
+ Type: |List|
+ Default: `['*']`
+
+ The checks to enable for clang-tidy with the `-checks` argument.
+
+ All options will be joined with commas, and escaped appropriately for
+ the shell. The `-checks` flag can be removed entirely by setting this
+ option to an empty List.
+
+
g:ale_cpp_clangtidy_options *g:ale_cpp_clangtidy_options*
*b:ale_cpp_clangtidy_options*
Type: |String|
- Default: `'-std=c++14 -Wall'`
+ Default: `''`
+
+ This variable can be changed to modify flags given to clang-tidy.
- This variable can be changed to modify flags given to clangtidy.
+ Setting this variable to a non-empty string will cause the `--` argument
+ to be passed to `clang-tidy`, which will mean that detection of
+ `compile_commands.json` files for compile command databases will be
+ disabled. Only set this option if you want to control compiler flags
+ entirely manually.
-------------------------------------------------------------------------------
diff --git a/doc/ale-kotlin.txt b/doc/ale-kotlin.txt
new file mode 100644
index 00000000..04efaeaf
--- /dev/null
+++ b/doc/ale-kotlin.txt
@@ -0,0 +1,65 @@
+===============================================================================
+ALE Kotlin Integration *ale-kotlin-options*
+ *ale-integration-kotlin*
+
+-------------------------------------------------------------------------------
+Integration Information
+
+ Make sure your setup has support for the kotlin file type. A filetype plugin
+ can be found here: https://github.com/udalov/kotlin-vim
+
+
+ Note: Make sure you have a working kotlin compiler
+
+
+-------------------------------------------------------------------------------
+kotlinc *ale-kotlin-kotlinc*
+
+g:ale_kotlin_kotlinc_options *g:ale_kotlin_kotlinc_options*
+ Type: |String|
+ Default: `''`
+
+ Additional options to pass to the kotlin compiler
+
+g:ale_kotlin_kotlinc_enable_config *g:ale_kotlin_kotlinc_enable_config*
+ Type: |Number|
+ Default: `0`
+
+ Setting this variable to `1` tells the linter to load a configuration file.
+ This should be set in your vimrc
+
+g:ale_kotlin_kotlinc_config_file *g:ale_kotlin_kotlinc_config_file*
+ Type: |String|
+ Default: `'.ale_kotlin_kotlinc_config'`
+
+ Filename of the configuration file. This should be set in your vimrc
+
+g:ale_kotlin_kotlinc_classpath *g:ale_kotlin_kotlinc_classpath*
+ Type: |String|
+ Default: `''`
+
+ A string containing the paths (separated by the appropriate path separator)
+ of the source directories.
+
+g:ale_kotlin_kotlinc_sourcepath *g:ale_kotlin_kotlinc_sourcepath*
+ Type: |String|
+ Default: `''`
+
+ A string containing the paths (separated by space) of the source
+ directories.
+
+g:ale_kotlin_kotlinc_use_module_file *g:ale_kotlin_kotlinc_use_module_file*
+ Type: |Number|
+ Default: `0`
+
+ This option indicates whether the linter should use a module file. It is off
+ by default.
+
+g:ale_kotlin_kotlinc_module_filename *g:ale_kotlin_kotlinc_module_filename*
+ Type: |String|
+ Default: `'module.xml'`
+
+ The filename of the module file that the linter should pass to the kotlin
+ compiler.
+
+ vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
diff --git a/doc/ale.txt b/doc/ale.txt
index d8573ef1..01258cad 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -46,6 +46,8 @@ CONTENTS *ale-contents*
jshint..............................|ale-javascript-jshint|
standard............................|ale-javascript-standard|
xo..................................|ale-javascript-xo|
+ kotlin................................|ale-kotlin-options|
+ kotlinc.............................|ale-kotlin-kotlinc|
lua...................................|ale-lua-options|
luacheck............................|ale-lua-luacheck|
ocaml.................................|ale-ocaml-options|
@@ -139,6 +141,7 @@ The following languages and tools are supported.
* Java: 'javac'
* JavaScript: 'eslint', 'jscs', 'jshint', 'flow', 'xo'
* JSON: 'jsonlint'
+* Kotlin: 'kotlinc'
* LaTeX: 'chktex', 'lacheck'
* Lua: 'luacheck'
* Markdown: 'mdl', 'proselint', 'vale'
diff --git a/test/command_callback/cppcheck_paths/one/compile_commands.json b/test/command_callback/cppcheck_paths/one/compile_commands.json
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/cppcheck_paths/one/compile_commands.json
diff --git a/test/command_callback/cppcheck_paths/one/two/three/file.c b/test/command_callback/cppcheck_paths/one/two/three/file.c
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/cppcheck_paths/one/two/three/file.c
diff --git a/test/command_callback/cppcheck_paths/one/two/three/file.cpp b/test/command_callback/cppcheck_paths/one/two/three/file.cpp
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/cppcheck_paths/one/two/three/file.cpp
diff --git a/test/command_callback/test_clang_tidy_command_callback.vader b/test/command_callback/test_clang_tidy_command_callback.vader
new file mode 100644
index 00000000..46d8a3a6
--- /dev/null
+++ b/test/command_callback/test_clang_tidy_command_callback.vader
@@ -0,0 +1,31 @@
+Before:
+ Save g:ale_cpp_clangtidy_checks
+ Save g:ale_cpp_clangtidy_options
+ runtime ale_linters/cpp/clangtidy.vim
+
+After:
+ Restore
+ call ale#linter#Reset()
+
+Execute(The clangtidy command default should be correct):
+ AssertEqual
+ \ 'clang-tidy -checks=''*'' %s',
+ \ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
+
+Execute(You should be able to remove the -checks option for clang-tidy):
+ let g:ale_cpp_clangtidy_checks = []
+ AssertEqual
+ \ 'clang-tidy %s',
+ \ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
+
+Execute(You should be able to set other checks for clang-tidy):
+ let g:ale_cpp_clangtidy_checks = ['-*', 'clang-analyzer-*']
+ AssertEqual
+ \ 'clang-tidy -checks=''-*,clang-analyzer-*'' %s',
+ \ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
+
+Execute(You should be able to manually set compiler flags for clang-tidy):
+ let g:ale_cpp_clangtidy_options = '-Wall'
+ AssertEqual
+ \ 'clang-tidy -checks=''*'' %s -- -Wall',
+ \ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
diff --git a/test/command_callback/test_cppcheck_command_callbacks.vader b/test/command_callback/test_cppcheck_command_callbacks.vader
new file mode 100644
index 00000000..665b4f13
--- /dev/null
+++ b/test/command_callback/test_cppcheck_command_callbacks.vader
@@ -0,0 +1,40 @@
+Before:
+ silent! cd /testplugin/test/command_callback
+ let b:dir = getcwd()
+
+After:
+ silent execute 'cd ' . fnameescape(b:dir)
+ unlet! b:dir
+ call ale#linter#Reset()
+
+Execute(The default C cppcheck command should be correct):
+ runtime ale_linters/c/cppcheck.vim
+
+ AssertEqual
+ \ 'cppcheck -q --language=c --enable=style %t',
+ \ ale_linters#c#cppcheck#GetCommand(bufnr(''))
+
+Execute(cppcheck for C should detect compile_commands.json files):
+ runtime ale_linters/c/cppcheck.vim
+ cd cppcheck_paths/one
+
+ AssertEqual
+ \ 'cd ' . fnameescape(b:dir . '/cppcheck_paths/one') . ' && '
+ \ . 'cppcheck -q --language=c --project=compile_commands.json --enable=style %t',
+ \ ale_linters#c#cppcheck#GetCommand(bufnr(''))
+
+Execute(The default C++ cppcheck command should be correct):
+ runtime ale_linters/cpp/cppcheck.vim
+
+ AssertEqual
+ \ 'cppcheck -q --language=c++ --enable=style %t',
+ \ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))
+
+Execute(cppcheck for C++ should detect compile_commands.json files):
+ runtime ale_linters/cpp/cppcheck.vim
+ cd cppcheck_paths/one
+
+ AssertEqual
+ \ 'cd ' . fnameescape(b:dir . '/cppcheck_paths/one') . ' && '
+ \ . 'cppcheck -q --language=c++ --project=compile_commands.json --enable=style %t',
+ \ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))