From 5d4611d70d53bcede53a4954470f6c163079d793 Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Sun, 9 Jul 2017 19:14:51 -0700 Subject: [PATCH] Use go tool vet to use vetflags Fixes #1073 --- src/goCheck.ts | 3 +-- test/fixtures/errorsTest/errors.go | 1 + test/go.test.ts | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/goCheck.ts b/src/goCheck.ts index 2cddb367..36471f74 100644 --- a/src/goCheck.ts +++ b/src/goCheck.ts @@ -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; } diff --git a/test/fixtures/errorsTest/errors.go b/test/fixtures/errorsTest/errors.go index 18d6162d..f9702abd 100644 --- a/test/fixtures/errorsTest/errors.go +++ b/test/fixtures/errorsTest/errors.go @@ -6,6 +6,7 @@ import ( func Print2(txt string) { fmt.Println(txt) + fmt.Println("%s") } func main2() { prin("Hello") diff --git a/test/go.test.ts b/test/go.test.ts index aaf3044c..1c1ae5a5 100644 --- a/test/go.test.ts +++ b/test/go.test.ts @@ -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) { @@ -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) => {