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

Commit

Permalink
Use go tool vet to use vetflags Fixes #1073
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Jul 10, 2017
1 parent cf6a40d commit 5d4611d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/goCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,10 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration)

if (!!goConfig['vetOnSave'] && goConfig['vetOnSave'] !== 'off') {
let vetFlags = goConfig['vetFlags'] || [];
let vetArgs = ['vet', ...vetFlags];
let vetArgs = ['tool', 'vet', ...vetFlags, '.'];
let vetWorkDir = cwd;

if (goConfig['vetOnSave'] === 'workspace') {
vetArgs.push('./...');
vetWorkDir = vscode.workspace.rootPath;
}

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/errorsTest/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

func Print2(txt string) {
fmt.Println(txt)
fmt.Println("%s")
}
func main2() {
prin("Hello")
Expand Down
20 changes: 13 additions & 7 deletions test/go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,16 @@ It returns the number of bytes written and any write error encountered.
});

test('Error checking', (done) => {
let config = vscode.workspace.getConfiguration('go');
let config = Object.create(vscode.workspace.getConfiguration('go'), {
'vetOnSave': { value: 'package' },
'vetFlags': { value: ['-all'] },
'lintTool': { value: 'golint' },
'lintFlags': { value: [] }
});
let expected = [
{ line: 7, severity: 'warning', msg: 'exported function Print2 should have comment or be unexported' },
// { line: 7, severity: 'warning', msg: 'no formatting directive in Printf call' },
{ line: 11, severity: 'error', msg: 'undefined: prin' },
{ line: 9, severity: 'warning', msg: 'possible formatting directive in Println call' },
{ line: 12, severity: 'error', msg: 'undefined: prin' },
];
getGoVersion().then(version => {
if (version.major === 1 && version.minor < 6) {
Expand Down Expand Up @@ -409,12 +414,13 @@ It returns the number of bytes written and any write error encountered.

let config = Object.create(vscode.workspace.getConfiguration('go'), {
'lintTool': { value: 'gometalinter' },
'lintFlags': { value: ['--disable-all', '--enable=varcheck', '--enable=errcheck']}
'lintFlags': { value: ['--disable-all', '--enable=varcheck', '--enable=errcheck'] },
'vetOnSave': { value: 'off' },
'buildOnSave': { value: 'off' }
});
let expected = [
{ line: 11, severity: 'warning', msg: 'error return value not checked (undeclared name: prin) (errcheck)' },
{ line: 11, severity: 'error', msg: 'undefined: prin' },
{ line: 11, severity: 'warning', msg: 'unused variable or constant undeclared name: prin (varcheck)' },
{ line: 12, severity: 'warning', msg: 'error return value not checked (undeclared name: prin) (errcheck)' },
{ line: 12, severity: 'warning', msg: 'unused variable or constant undeclared name: prin (varcheck)' },
];
return check(path.join(fixturePath, 'errorsTest', 'errors.go'), config).then(diagnostics => {
let sortedDiagnostics = diagnostics.sort((a, b) => {
Expand Down

0 comments on commit 5d4611d

Please sign in to comment.