summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2017-04-15 21:09:23 +0100
committerGitHub <noreply@github.com>2017-04-15 21:09:23 +0100
commit35c831dd2c9c5316d64aebc7df9fae9765af716c (patch)
treec5e308223badfec889422833354cd20779c082c5
parent296ae92da4c85f7bb607ec39f431bc1bdd5eeab4 (diff)
parentf0d76bc298778789072b87b73789141c750f1f50 (diff)
downloadale-35c831dd2c9c5316d64aebc7df9fae9765af716c.zip
Merge pull request #471 from breed808/gometalinter
Add gometalinter linter for go files
-rw-r--r--README.md2
-rw-r--r--ale_linters/go/gometalinter.vim56
-rw-r--r--autoload/ale/linter.vim1
-rw-r--r--doc/ale-go.txt37
-rw-r--r--doc/ale.txt4
5 files changed, 98 insertions, 2 deletions
diff --git a/README.md b/README.md
index ed39e25a..c534d51a 100644
--- a/README.md
+++ b/README.md
@@ -72,7 +72,7 @@ name. That seems to be the fairest way to arrange this table.
| Elm | [elm-make](https://github.com/elm-lang/elm-make) |
| Erlang | [erlc](http://erlang.org/doc/man/erlc.html) |
| Fortran | [gcc](https://gcc.gnu.org/) |
-| Go | [gofmt -e](https://golang.org/cmd/gofmt/), [go vet](https://golang.org/cmd/vet/), [golint](https://godoc.org/github.com/golang/lint), [go build](https://golang.org/cmd/go/), [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple), [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) |
+| Go | [gofmt -e](https://golang.org/cmd/gofmt/), [go vet](https://golang.org/cmd/vet/), [golint](https://godoc.org/github.com/golang/lint), [gometalinter](https://github.com/alecthomas/gometalinter), [go build](https://golang.org/cmd/go/), [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple), [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) |
| Haml | [haml-lint](https://github.com/brigade/haml-lint)
| Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) |
| Haskell | [ghc](https://www.haskell.org/ghc/), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools) |
diff --git a/ale_linters/go/gometalinter.vim b/ale_linters/go/gometalinter.vim
new file mode 100644
index 00000000..8dbd8b26
--- /dev/null
+++ b/ale_linters/go/gometalinter.vim
@@ -0,0 +1,56 @@
+" Author: Ben Reedy <https://github.com/breed808>
+" Description: Adds support for the gometalinter suite for Go files
+
+if !exists('g:ale_go_gometalinter_options')
+ let g:ale_go_gometalinter_options = ''
+endif
+
+function! ale_linters#go#gometalinter#GetCommand(buffer) abort
+ return 'gometalinter '
+ \ . g:ale_go_gometalinter_options
+ \ . ' ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h'))
+endfunction
+
+function! ale_linters#go#gometalinter#Handler(buffer, lines) abort
+ " Matches patterns line the following:
+ "
+ " file.go:27: missing argument for Printf("%s"): format reads arg 2, have only 1 args
+ " file.go:53:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
+ " file.go:5:2: expected declaration, found 'STRING' "log"
+
+ " gometalinter returns relative paths so use tail of filename as part of pattern matcher
+ let l:filename = fnamemodify(bufname(a:buffer), ':t')
+ let l:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+'
+ let l:pattern = '^' . l:path_pattern . ':\(\d\+\):\?\(\d\+\)\?:\?:\?\(warning\|error\):\?\s\*\?\(.\+\)$'
+ let l:output = []
+
+ for l:line in a:lines
+ let l:match = matchlist(l:line, l:pattern)
+
+ " Omit errors from files other than the one currently open
+ if len(l:match) == 0 || l:line !~ l:filename
+ continue
+ endif
+
+ " vcol is Needed to indicate that the column is a character.
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:match[1] + 0,
+ \ 'vcol': 0,
+ \ 'col': l:match[2] + 0,
+ \ 'text': l:match[4],
+ \ 'type': tolower(l:match[3]) ==# 'warning' ? 'W' : 'E',
+ \ 'nr': -1,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('go', {
+\ 'name': 'gometalinter',
+\ 'executable': 'gometalinter',
+\ 'command_callback': 'ale_linters#go#gometalinter#GetCommand',
+\ 'callback': 'ale_linters#go#gometalinter#Handler',
+\ 'lint_file': 1,
+\})
diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim
index b13aa1c9..dc42c52a 100644
--- a/autoload/ale/linter.vim
+++ b/autoload/ale/linter.vim
@@ -22,6 +22,7 @@ let s:default_ale_linter_aliases = {
" Only cargo is enabled for Rust by default.
let s:default_ale_linters = {
\ 'csh': ['shell'],
+\ 'go': ['go build', 'gofmt', 'golint', 'gosimple', 'go vet', 'staticcheck'],
\ 'help': [],
\ 'rust': ['cargo'],
\ 'text': [],
diff --git a/doc/ale-go.txt b/doc/ale-go.txt
new file mode 100644
index 00000000..3ae82e80
--- /dev/null
+++ b/doc/ale-go.txt
@@ -0,0 +1,37 @@
+===============================================================================
+ALE Go Integration *ale-go-options*
+
+
+-------------------------------------------------------------------------------
+Integration Information
+
+The `gometalinter` linter is disabled by default, and all other Go linters
+supported by ALE are enabled by default. To enable `gometalinter`, update
+|g:ale_linters| as appropriate:
+
+>
+ " Enable all of the linters you want for Go.
+ let g:ale_linters = {'go': ['gometalinter', 'gofmt']}
+<
+
+-------------------------------------------------------------------------------
+gometalinter *ale-go-gometalinter*
+
+g:ale_go_gometalinter_enabled *g:ale_go_gometalinter_enabled*
+
+ Type: |Integer|
+ Default: 0
+
+ This variable can be change to enable gometalinter for go files.
+
+
+g:ale_go_gometalinter_options *g:ale_go_gometalinter_options*
+
+ Type: |String|
+ Default: `''`
+
+ This variable can be changed to alter the command-line arguments to the
+ gometalinter invocation.
+
+-------------------------------------------------------------------------------
+ vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
diff --git a/doc/ale.txt b/doc/ale.txt
index 7ae9b2a6..b82fd5f5 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -31,6 +31,8 @@ CONTENTS *ale-contents*
erlc................................|ale-erlang-erlc|
fortran...............................|ale-fortran-options|
gcc.................................|ale-fortran-gcc|
+ go....................................|ale-go-options|
+ gometalinter........................|ale-go-gometalinter|
handlebars............................|ale-handlebars-options|
ember-template-lint.................|ale-handlebars-embertemplatelint|
html..................................|ale-html-options|
@@ -124,7 +126,7 @@ The following languages and tools are supported.
* Elm: 'elm-make'
* Erlang: 'erlc'
* Fortran: 'gcc'
-* Go: 'gofmt -e', 'go vet', 'golint', 'go build', 'gosimple', 'staticcheck'
+* Go: 'gofmt', 'go vet', 'golint', 'go build', 'gosimple', 'staticcheck'
* Haml: 'hamllint'
* Handlebars: 'ember-template-lint'
* Haskell: 'ghc', 'hlint'