diff options
Diffstat (limited to 'ale_linters')
-rw-r--r-- | ale_linters/asciidoc/languagetool.vim | 5 | ||||
-rw-r--r-- | ale_linters/c/cc.vim | 53 | ||||
-rw-r--r-- | ale_linters/c/clang.vim | 24 | ||||
-rw-r--r-- | ale_linters/c/gcc.vim | 28 | ||||
-rw-r--r-- | ale_linters/cpp/cc.vim | 53 | ||||
-rw-r--r-- | ale_linters/cpp/clang.vim | 24 | ||||
-rw-r--r-- | ale_linters/cpp/gcc.vim | 29 | ||||
-rw-r--r-- | ale_linters/elixir/credo.vim | 2 | ||||
-rw-r--r-- | ale_linters/markdown/markdownlint.vim | 13 | ||||
-rw-r--r-- | ale_linters/ocaml/ols.vim | 2 | ||||
-rw-r--r-- | ale_linters/reason/ols.vim | 2 | ||||
-rw-r--r-- | ale_linters/sh/shell.vim | 2 | ||||
-rw-r--r-- | ale_linters/swift/swiftformat.vim | 62 |
13 files changed, 189 insertions, 110 deletions
diff --git a/ale_linters/asciidoc/languagetool.vim b/ale_linters/asciidoc/languagetool.vim new file mode 100644 index 00000000..f16df6c0 --- /dev/null +++ b/ale_linters/asciidoc/languagetool.vim @@ -0,0 +1,5 @@ +" Author: Horacio Sanson (hsanson [ät] gmail.com) +" Description: languagetool for asciidoc files, copied from markdown. + + +call ale#handlers#languagetool#DefineLinter('asciidoctor') diff --git a/ale_linters/c/cc.vim b/ale_linters/c/cc.vim new file mode 100644 index 00000000..6d920ab0 --- /dev/null +++ b/ale_linters/c/cc.vim @@ -0,0 +1,53 @@ +" Author: w0rp <devw0rp@gmail.com> +" Description: A C compiler linter for C files with gcc/clang, etc. + +call ale#Set('c_cc_executable', '<auto>') +call ale#Set('c_cc_options', '-std=c11 -Wall') + +function! ale_linters#c#cc#GetExecutable(buffer) abort + let l:executable = ale#Var(a:buffer, 'c_cc_executable') + + " Default to either clang or gcc. + if l:executable is# '<auto>' + if ale#engine#IsExecutable(a:buffer, 'clang') + let l:executable = 'clang' + else + let l:executable = 'gcc' + endif + endif + + return l:executable +endfunction + +function! ale_linters#c#cc#GetCommand(buffer, output) abort + let l:cflags = ale#c#GetCFlags(a:buffer, a:output) + let l:ale_flags = ale#Var(a:buffer, 'c_cc_options') + + if l:cflags =~# '-std=' + let l:ale_flags = substitute( + \ l:ale_flags, + \ '-std=\(c\|gnu\)[0-9]\{2\}', + \ '', + \ 'g') + endif + + " -iquote with the directory the file is in makes #include work for + " headers in the same directory. + " + " `-o /dev/null` or `-o null` is needed to catch all errors, + " -fsyntax-only doesn't catch everything. + return '%e -S -x c' + \ . ' -o ' . g:ale#util#nul_file + \ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) + \ . ale#Pad(l:cflags) + \ . ale#Pad(l:ale_flags) . ' -' +endfunction + +call ale#linter#Define('c', { +\ 'name': 'cc', +\ 'aliases': ['gcc', 'clang'], +\ 'output_stream': 'stderr', +\ 'executable': function('ale_linters#c#cc#GetExecutable'), +\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#cc#GetCommand'))}, +\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes', +\}) diff --git a/ale_linters/c/clang.vim b/ale_linters/c/clang.vim deleted file mode 100644 index 681101fc..00000000 --- a/ale_linters/c/clang.vim +++ /dev/null @@ -1,24 +0,0 @@ -" Author: Masahiro H https://github.com/mshr-h -" Description: clang linter for c files - -call ale#Set('c_clang_executable', 'clang') -call ale#Set('c_clang_options', '-std=c11 -Wall') - -function! ale_linters#c#clang#GetCommand(buffer, output) abort - let l:cflags = ale#c#GetCFlags(a:buffer, a:output) - - " -iquote with the directory the file is in makes #include work for - " headers in the same directory. - return '%e -S -x c -fsyntax-only' - \ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) - \ . ale#Pad(l:cflags) - \ . ale#Pad(ale#Var(a:buffer, 'c_clang_options')) . ' -' -endfunction - -call ale#linter#Define('c', { -\ 'name': 'clang', -\ 'output_stream': 'stderr', -\ 'executable': {b -> ale#Var(b, 'c_clang_executable')}, -\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#clang#GetCommand'))}, -\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes', -\}) diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim deleted file mode 100644 index 1df1018e..00000000 --- a/ale_linters/c/gcc.vim +++ /dev/null @@ -1,28 +0,0 @@ -" Author: w0rp <devw0rp@gmail.com> -" Description: gcc linter for c files - -call ale#Set('c_gcc_executable', 'gcc') -call ale#Set('c_gcc_options', '-std=c11 -Wall') - -function! ale_linters#c#gcc#GetCommand(buffer, output) abort - let l:cflags = ale#c#GetCFlags(a:buffer, a:output) - - " -iquote with the directory the file is in makes #include work for - " headers in the same directory. - " - " `-o /dev/null` or `-o null` is needed to catch all errors, - " -fsyntax-only doesn't catch everything. - return '%e -S -x c' - \ . ' -o ' . g:ale#util#nul_file - \ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) - \ . ale#Pad(l:cflags) - \ . ale#Pad(ale#Var(a:buffer, 'c_gcc_options')) . ' -' -endfunction - -call ale#linter#Define('c', { -\ 'name': 'gcc', -\ 'output_stream': 'stderr', -\ 'executable': {b -> ale#Var(b, 'c_gcc_executable')}, -\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#gcc#GetCommand'))}, -\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes', -\}) diff --git a/ale_linters/cpp/cc.vim b/ale_linters/cpp/cc.vim new file mode 100644 index 00000000..eed3898f --- /dev/null +++ b/ale_linters/cpp/cc.vim @@ -0,0 +1,53 @@ +" Author: w0rp <devw0rp@gmail.com> +" Description: A C++ compiler linter for C++ files with gcc/clang, etc. + +call ale#Set('cpp_cc_executable', '<auto>') +call ale#Set('cpp_cc_options', '-std=c++14 -Wall') + +function! ale_linters#cpp#cc#GetExecutable(buffer) abort + let l:executable = ale#Var(a:buffer, 'cpp_cc_executable') + + " Default to either clang++ or gcc. + if l:executable is# '<auto>' + if ale#engine#IsExecutable(a:buffer, 'clang++') + let l:executable = 'clang++' + else + let l:executable = 'gcc' + endif + endif + + return l:executable +endfunction + +function! ale_linters#cpp#cc#GetCommand(buffer, output) abort + let l:cflags = ale#c#GetCFlags(a:buffer, a:output) + let l:ale_flags = ale#Var(a:buffer, 'cpp_cc_options') + + if l:cflags =~# '-std=' + let l:ale_flags = substitute( + \ l:ale_flags, + \ '-std=\(c\|gnu\)++[0-9]\{2\}', + \ '', + \ 'g') + endif + + " -iquote with the directory the file is in makes #include work for + " headers in the same directory. + " + " `-o /dev/null` or `-o null` is needed to catch all errors, + " -fsyntax-only doesn't catch everything. + return '%e -S -x c++' + \ . ' -o ' . g:ale#util#nul_file + \ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) + \ . ale#Pad(l:cflags) + \ . ale#Pad(l:ale_flags) . ' -' +endfunction + +call ale#linter#Define('cpp', { +\ 'name': 'cc', +\ 'aliases': ['gcc', 'clang', 'g++', 'clang++'], +\ 'output_stream': 'stderr', +\ 'executable': function('ale_linters#cpp#cc#GetExecutable'), +\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#cc#GetCommand'))}, +\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes', +\}) diff --git a/ale_linters/cpp/clang.vim b/ale_linters/cpp/clang.vim deleted file mode 100644 index e48291eb..00000000 --- a/ale_linters/cpp/clang.vim +++ /dev/null @@ -1,24 +0,0 @@ -" Author: Tomota Nakamura <https://github.com/tomotanakamura> -" Description: clang linter for cpp files - -call ale#Set('cpp_clang_executable', 'clang++') -call ale#Set('cpp_clang_options', '-std=c++14 -Wall') - -function! ale_linters#cpp#clang#GetCommand(buffer, output) abort - let l:cflags = ale#c#GetCFlags(a:buffer, a:output) - - " -iquote with the directory the file is in makes #include work for - " headers in the same directory. - return '%e -S -x c++ -fsyntax-only' - \ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) - \ . ale#Pad(l:cflags) - \ . ale#Pad(ale#Var(a:buffer, 'cpp_clang_options')) . ' -' -endfunction - -call ale#linter#Define('cpp', { -\ 'name': 'clang', -\ 'output_stream': 'stderr', -\ 'executable': {b -> ale#Var(b, 'cpp_clang_executable')}, -\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#clang#GetCommand'))}, -\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes', -\}) diff --git a/ale_linters/cpp/gcc.vim b/ale_linters/cpp/gcc.vim deleted file mode 100644 index 108d6d70..00000000 --- a/ale_linters/cpp/gcc.vim +++ /dev/null @@ -1,29 +0,0 @@ -" Author: geam <mdelage@student.42.fr> -" Description: gcc linter for cpp files -" -call ale#Set('cpp_gcc_executable', 'gcc') -call ale#Set('cpp_gcc_options', '-std=c++14 -Wall') - -function! ale_linters#cpp#gcc#GetCommand(buffer, output) abort - let l:cflags = ale#c#GetCFlags(a:buffer, a:output) - - " -iquote with the directory the file is in makes #include work for - " headers in the same directory. - " - " `-o /dev/null` or `-o null` is needed to catch all errors, - " -fsyntax-only doesn't catch everything. - return '%e -S -x c++' - \ . ' -o ' . g:ale#util#nul_file - \ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) - \ . ale#Pad(l:cflags) - \ . ale#Pad(ale#Var(a:buffer, 'cpp_gcc_options')) . ' -' -endfunction - -call ale#linter#Define('cpp', { -\ 'name': 'gcc', -\ 'aliases': ['g++'], -\ 'output_stream': 'stderr', -\ 'executable': {b -> ale#Var(b, 'cpp_gcc_executable')}, -\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#gcc#GetCommand'))}, -\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes', -\}) diff --git a/ale_linters/elixir/credo.vim b/ale_linters/elixir/credo.vim index 317ecab3..7c298502 100644 --- a/ale_linters/elixir/credo.vim +++ b/ale_linters/elixir/credo.vim @@ -46,7 +46,7 @@ function! ale_linters#elixir#credo#GetMode() abort endfunction function! ale_linters#elixir#credo#GetCommand(buffer) abort - let l:project_root = ale#handlers#elixir#FindMixProjectRoot(a:buffer) + let l:project_root = ale#handlers#elixir#FindMixUmbrellaRoot(a:buffer) let l:mode = ale_linters#elixir#credo#GetMode() return ale#path#CdString(l:project_root) diff --git a/ale_linters/markdown/markdownlint.vim b/ale_linters/markdown/markdownlint.vim index e935cbfe..7a293938 100644 --- a/ale_linters/markdown/markdownlint.vim +++ b/ale_linters/markdown/markdownlint.vim @@ -1,11 +1,22 @@ " Author: Ty-Lucas Kelley <tylucaskelley@gmail.com> " Description: Adds support for markdownlint +call ale#Set('markdown_markdownlint_options', '') + +function! ale_linters#markdown#markdownlint#GetCommand(buffer) abort + let l:executable = 'markdownlint' + + let l:options = ale#Var(a:buffer, 'markdown_markdownlint_options') + + return ale#Escape(l:executable) + \ . (!empty(l:options) ? ' ' . l:options : '') . ' %s' +endfunction + call ale#linter#Define('markdown', { \ 'name': 'markdownlint', \ 'executable': 'markdownlint', \ 'lint_file': 1, \ 'output_stream': 'both', -\ 'command': 'markdownlint %s', +\ 'command': function('ale_linters#markdown#markdownlint#GetCommand'), \ 'callback': 'ale#handlers#markdownlint#Handle' \}) diff --git a/ale_linters/ocaml/ols.vim b/ale_linters/ocaml/ols.vim index d8208c52..ec71bdb4 100644 --- a/ale_linters/ocaml/ols.vim +++ b/ale_linters/ocaml/ols.vim @@ -9,6 +9,6 @@ call ale#linter#Define('ocaml', { \ 'lsp': 'stdio', \ 'executable': function('ale#handlers#ols#GetExecutable'), \ 'command': function('ale#handlers#ols#GetCommand'), -\ 'language_callback': 'ale#handlers#ols#GetLanguage', +\ 'language': function('ale#handlers#ols#GetLanguage'), \ 'project_root': function('ale#handlers#ols#GetProjectRoot'), \}) diff --git a/ale_linters/reason/ols.vim b/ale_linters/reason/ols.vim index 66137e1b..9fbd9b4f 100644 --- a/ale_linters/reason/ols.vim +++ b/ale_linters/reason/ols.vim @@ -9,6 +9,6 @@ call ale#linter#Define('reason', { \ 'lsp': 'stdio', \ 'executable': function('ale#handlers#ols#GetExecutable'), \ 'command': function('ale#handlers#ols#GetCommand'), -\ 'language_callback': 'ale#handlers#ols#GetLanguage', +\ 'language': function('ale#handlers#ols#GetLanguage'), \ 'project_root': function('ale#handlers#ols#GetProjectRoot'), \}) diff --git a/ale_linters/sh/shell.vim b/ale_linters/sh/shell.vim index 171fe64e..73ab3608 100644 --- a/ale_linters/sh/shell.vim +++ b/ale_linters/sh/shell.vim @@ -1,5 +1,5 @@ " Author: w0rp <devw0rp@gmail.com> -" Description: Lints sh files using bash -n +" Description: Lints shell files by invoking the shell with -n " Backwards compatibility if exists('g:ale_linters_sh_shell_default_shell') diff --git a/ale_linters/swift/swiftformat.vim b/ale_linters/swift/swiftformat.vim new file mode 100644 index 00000000..2504511a --- /dev/null +++ b/ale_linters/swift/swiftformat.vim @@ -0,0 +1,62 @@ +" Author: Klaas Pieter Annema <https://github.com/klaaspieter> +" Description: Support for swift-format https://github.com/apple/swift-format + +let s:default_executable = 'swift-format' +call ale#Set('swift_swiftformat_executable', s:default_executable) + +function! ale_linters#swift#swiftformat#UseSwift(buffer) abort + let l:swift_config = ale#path#FindNearestFile(a:buffer, 'Package.swift') + let l:executable = ale#Var(a:buffer, 'swift_swiftformat_executable') + + return !empty(l:swift_config) && l:executable is# s:default_executable +endfunction + +function! ale_linters#swift#swiftformat#GetExecutable(buffer) abort + if ale_linters#swift#swiftformat#UseSwift(a:buffer) + return 'swift' + endif + + return ale#Var(a:buffer, 'swift_swiftformat_executable') +endfunction + +function! ale_linters#swift#swiftformat#GetCommand(buffer) abort + let l:executable = ale_linters#swift#swiftformat#GetExecutable(a:buffer) + let l:args = '--mode lint %t' + + if ale_linters#swift#swiftformat#UseSwift(a:buffer) + let l:args = 'run swift-format' . ' ' . l:args + endif + + return ale#Escape(l:executable) . ' ' . l:args +endfunction + +function! ale_linters#swift#swiftformat#Handle(buffer, lines) abort + " Matches lines of the following pattern: + " + " Sources/main.swift:4:21: warning: [DoNotUseSemicolons]: remove ';' and move the next statement to the new line + " Sources/main.swift:3:12: warning: [Spacing]: remove 1 space + let l:pattern = '\v^.*:(\d+):(\d+): (\S+) \[(\S+)\]: (.*)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'lnum': l:match[1] + 0, + \ 'col': l:match[2] + 0, + \ 'type': l:match[3] is# 'error' ? 'E' : 'W', + \ 'code': l:match[4], + \ 'text': l:match[5], + \}) + endfor + + return l:output +endfunction + + +call ale#linter#Define('swift', { +\ 'name': 'swift-format', +\ 'executable': function('ale_linters#swift#swiftformat#GetExecutable'), +\ 'command': function('ale_linters#swift#swiftformat#GetCommand'), +\ 'output_stream': 'stderr', +\ 'language': 'swift', +\ 'callback': 'ale_linters#swift#swiftformat#Handle' +\}) |