From 797331cd7f7ee9da1dffb239f833b7fa8c01c8b6 Mon Sep 17 00:00:00 2001 From: Peter Fern Date: Sat, 26 May 2018 13:02:38 +1000 Subject: [PATCH 1/2] Add support for golangci-lint as the lintTool --- README.md | 3 +++ package.json | 3 ++- src/goInstallTools.ts | 1 + src/goLint.ts | 5 +++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37935d6e7..3a6abe914 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,9 @@ If you want to run only specific linters (some linters are slow), you can modify Alternatively, you can use [megacheck](https://github.com/dominikh/go-tools/tree/master/cmd/megacheck) which may have significantly better performance than `gometalinter`, while only supporting a subset of the tools. +Another alternative is [golangci-lint](https://github.com/golangci/golangci-lint) which shares some of the performance +characteristics of megacheck, but supports a broader range of tools. + Finally, the result of those linters will show right in the code (locations with suggestions will be underlined), as well as in the output pane. diff --git a/package.json b/package.json index 7026a395a..0feba1479 100644 --- a/package.json +++ b/package.json @@ -478,7 +478,8 @@ "enum": [ "golint", "gometalinter", - "megacheck" + "megacheck", + "golangci-lint" ] }, "go.lintFlags": { diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index a6216056e..7af88a2e6 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -38,6 +38,7 @@ const allTools: { [key: string]: string } = { 'gotests': 'github.com/cweill/gotests/...', 'gometalinter': 'github.com/alecthomas/gometalinter', 'megacheck': 'honnef.co/go/tools/...', + 'golangci-lint': 'github.com/golangci/golangci-lint/cmd/golangci-lint', 'go-langserver': 'github.com/sourcegraph/go-langserver', 'dlv': 'github.com/derekparker/delve/cmd/dlv', 'fillstruct': 'github.com/davidrjenni/reftools/cmd/fillstruct' diff --git a/src/goLint.ts b/src/goLint.ts index 229410202..0d137d2d0 100644 --- a/src/goLint.ts +++ b/src/goLint.ts @@ -82,6 +82,11 @@ export function goLint(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfigurat lintEnv['GOPATH'] += path.delimiter + goConfig['toolsGopath']; } } + if (lintTool === 'golangci-lint') { + if (args.indexOf('run') === -1) { + args.unshift('run'); + } + } if (lintWorkspace && currentWorkspace) { args.push('./...'); From 898acf248dad5a7afa934b856d6a85a0c3f935ca Mon Sep 17 00:00:00 2001 From: golangci Date: Sat, 26 May 2018 11:00:55 +0300 Subject: [PATCH 2/2] small improvements for golangci-lint support --- README.md | 7 ++++++- src/goInstallTools.ts | 5 +++++ src/goLint.ts | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a6abe914..f840eaf58 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This extension adds rich language support for the Go language to VS Code, includ - Workspace symbol search (using `go-symbols`) - Rename (using `gorename`. Note: For Undo after rename to work in Windows you need to have `diff` tool in your path) - Build-on-save (using `go build` and `go test`) -- Lint-on-save (using `golint` or `gometalinter`) +- Lint-on-save (using `golint` or `gometalinter` or `megacheck` or `golangci-lint`) - Format on save as well as format manually (using `goreturns` or `goimports` or `gofmt`) - Generate unit tests skeleton (using `gotests`) - Add Imports (using `gopkgs`) @@ -92,6 +92,11 @@ may have significantly better performance than `gometalinter`, while only suppor Another alternative is [golangci-lint](https://github.com/golangci/golangci-lint) which shares some of the performance characteristics of megacheck, but supports a broader range of tools. +You can configure golangci-lint with `go.lintFlags`, for example to show issues only in new code and to enable all linters: + +```javascript + "go.lintFlags": ["--enable-all", "--new"], +``` Finally, the result of those linters will show right in the code (locations with suggestions will be underlined), as well as in the output pane. diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index 7af88a2e6..001e85220 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -60,6 +60,7 @@ const importantTools = [ 'golint', 'gometalinter', 'megacheck', + 'golangci-lint', 'dlv' ]; @@ -113,6 +114,10 @@ function getTools(goVersion: SemVersion): string[] { tools.push('megacheck'); } + if (goConfig['lintTool'] === 'golangci-lint') { + tools.push('golangci-lint'); + } + if (goConfig['useLanguageServer'] && process.platform !== 'win32') { tools.push('go-langserver'); } diff --git a/src/goLint.ts b/src/goLint.ts index 0d137d2d0..971b4d083 100644 --- a/src/goLint.ts +++ b/src/goLint.ts @@ -86,6 +86,10 @@ export function goLint(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfigurat if (args.indexOf('run') === -1) { args.unshift('run'); } + if (args.indexOf('--print-issued-lines=false') === -1) { + // print only file:number:column + args.push('--print-issued-lines=false'); + } } if (lintWorkspace && currentWorkspace) {