Skip to content

golangci-lint integration issue #411

Closed
@butuzov

Description

@butuzov

TL/DR
Warning message generated by nolintlint linter, brakes vscode-go problem reporting. this is caused by npm child_process executor logic. Current workaround to enable no error code argument supplied to vscode-go golangci-lint linter argumens (--issues-exit-code=0) .


What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go version go1.14.5 darwin/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.47.2
  • Check your installed extensions to get the version of the VS Code Go extension
    • none + golang.go
  • Run go env to get the go development environment details
    • doesn't matter.

Share the Go related settings you have added/edited

"go.lintTool": "golangci-lint",
"go.lintFlags": [
        "-c", ".golangci.yml"   # example https://github.com/butuzov/dots/blob/master/.golangci.yml
]

Describe the bug

This is an integration bug (found while working with golangci-lint) and prevents getting Problems found by linter.

It occurs if combinations of factors happen, If linter output has:

  1. Error_Code, StdErr and StdOut: it's (vscode-go) fails to report an code problems.
  2. Error_Code and StdOut: everything works.
  3. StdOut & StdErr, but no Error_Code: everything works.

Steps to reproduce the behavior:

  1. Create example.go

    package main
    
    func main() {}
    
    // there are no such linter "deaccode", it's a typo, but `nolintlint` linter will show warning (perfectly fine). 
    // and this is braks vsc-go 
    
    //nolint:deacdcode
    func add(a, b int) int {
    	a += 10
    	b += 11
    	return a + b
    }
    
    func nouse() {}
  2. Run VSCode against folder with this file with default settings () to get failed examples.

  3. Run VSCode against folder with this file with default settings + --issues-exit-code=0 in order to get working example.

An example of call to golangci-lint

golangci-lint run --disable-all -E=nolintlint -E=deadcode -E=wsl example.go

Suggestions?

  1. Add --issues-exit-code=0 to list of arguments passed to golangci-lint in addition to existing ones (added in steals mode by vscode-go)
  2. Adjust logic at https://github.com/golang/vscode-go/blob/master/src/util.ts#L726:L729 as per

Root of the problem

  1. node js child_process:
  • report an error, if stderr not empty, and return code is > 0
  • doesn't change err if stderr has output and return code is 0

test node.js script

const { execFile } = require('child_process');

let args = ['run', '--disable-all', '-E=nolintlint', '-E=deadcode', '-E=wsl'];
['issue.go', 'noissue.go'].forEach((file) => {
	['1', '0'].forEach((error_code_report) => {
		let testArgs = args.slice();
		testArgs.push(`--issues-exit-code=${error_code_report}`, file);

		execFile('golangci-lint', testArgs, (err, stdout, stderr) => {
			console.info('='.repeat(60));
			console.debug(testArgs);
			console.log('err', err);
			console.log('stdOut exists', stdout.length > 0);
			console.log('stdErr exists', stderr.length > 0);
		});
	});
});

run it

node test.js

against next files https://gist.github.com/butuzov/4a682fd28bc89c1bdb6f1cc7996e9cfb

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions