From 1167616726f9e995da9ac5b674cf6ded2d221855 Mon Sep 17 00:00:00 2001 From: Ben Reedy Date: Thu, 13 Apr 2017 19:25:35 +1000 Subject: [PATCH 1/3] Add gometalinter for go files Linter is disabled by default (see g:ale_go_gometalinter_enabled) as it conflicts with a number of established ALE linters (golint, govet, gosimple, staticcheck, etc). --- ale_linters/go/gometalinter.vim | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 ale_linters/go/gometalinter.vim diff --git a/ale_linters/go/gometalinter.vim b/ale_linters/go/gometalinter.vim new file mode 100644 index 0000000..3a827fd --- /dev/null +++ b/ale_linters/go/gometalinter.vim @@ -0,0 +1,61 @@ +" Author: Ben Reedy +" Description: Adds support for the gometalinter suite for Go files + +" Disable gometalinter by default +if !exists('g:ale_go_gometalinter_enabled') + let g:ale_go_gometalinter_enabled = 0 +endif + +if !exists('g:ale_go_gometalinter_options') + let g:ale_go_gometalinter_options = '' +endif + +function! ale_linters#go#gometalinter#GetCommand(buffer) abort + if g:ale_go_gometalinter_enabled == 1 + return 'gometalinter ' . g:ale_go_gometalinter_options . ' ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h')) + endif + return '' +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, +\}) From 54991f3082108cb41e5be06a068e3e0472b858b9 Mon Sep 17 00:00:00 2001 From: Ben Reedy Date: Thu, 13 Apr 2017 19:27:09 +1000 Subject: [PATCH 2/3] Add documentation for gometalinter --- README.md | 2 +- doc/ale-go.txt | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 doc/ale-go.txt diff --git a/README.md b/README.md index 9c513e5..7c55fac 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,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/doc/ale-go.txt b/doc/ale-go.txt new file mode 100644 index 0000000..e086bcd --- /dev/null +++ b/doc/ale-go.txt @@ -0,0 +1,25 @@ +=============================================================================== +ALE Go Integration *ale-go-options* + + +------------------------------------------------------------------------------- +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: From f0d76bc298778789072b87b73789141c750f1f50 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sat, 15 Apr 2017 21:04:43 +0100 Subject: [PATCH 3/3] Use g:ale_linters for turning gometalinter on, and update documentation as appropriate --- ale_linters/go/gometalinter.vim | 13 ++++--------- autoload/ale/linter.vim | 1 + doc/ale-go.txt | 12 ++++++++++++ doc/ale.txt | 4 +++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ale_linters/go/gometalinter.vim b/ale_linters/go/gometalinter.vim index 3a827fd..8dbd8b2 100644 --- a/ale_linters/go/gometalinter.vim +++ b/ale_linters/go/gometalinter.vim @@ -1,20 +1,14 @@ " Author: Ben Reedy " Description: Adds support for the gometalinter suite for Go files -" Disable gometalinter by default -if !exists('g:ale_go_gometalinter_enabled') - let g:ale_go_gometalinter_enabled = 0 -endif - if !exists('g:ale_go_gometalinter_options') let g:ale_go_gometalinter_options = '' endif function! ale_linters#go#gometalinter#GetCommand(buffer) abort - if g:ale_go_gometalinter_enabled == 1 - return 'gometalinter ' . g:ale_go_gometalinter_options . ' ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h')) - endif - return '' + return 'gometalinter ' + \ . g:ale_go_gometalinter_options + \ . ' ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h')) endfunction function! ale_linters#go#gometalinter#Handler(buffer, lines) abort @@ -49,6 +43,7 @@ function! ale_linters#go#gometalinter#Handler(buffer, lines) abort \ 'nr': -1, \}) endfor + return l:output endfunction diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim index eec9cf1..8b31381 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 index e086bcd..3ae82e8 100644 --- a/doc/ale-go.txt +++ b/doc/ale-go.txt @@ -2,6 +2,18 @@ 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* diff --git a/doc/ale.txt b/doc/ale.txt index 85409fc..e3ecb43 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| @@ -123,7 +125,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'