Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Add support for golangci-lint as the lintTool #1693

Merged
merged 2 commits into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -90,6 +90,14 @@ 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.
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.

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@
"enum": [
"golint",
"gometalinter",
"megacheck"
"megacheck",
"golangci-lint"
]
},
"go.lintFlags": {
Expand Down
6 changes: 6 additions & 0 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -59,6 +60,7 @@ const importantTools = [
'golint',
'gometalinter',
'megacheck',
'golangci-lint',
'dlv'
];

Expand Down Expand Up @@ -112,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');
}
Expand Down
9 changes: 9 additions & 0 deletions src/goLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ 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 (args.indexOf('--print-issued-lines=false') === -1) {
// print only file:number:column
args.push('--print-issued-lines=false');
}
}

if (lintWorkspace && currentWorkspace) {
args.push('./...');
Expand Down