Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing staticcheck rule activation #1649

Closed
marten-seemann opened this issue Jan 13, 2021 · 4 comments
Closed

Confusing staticcheck rule activation #1649

marten-seemann opened this issue Jan 13, 2021 · 4 comments
Labels
enhancement New feature or improvement

Comments

@marten-seemann
Copy link

Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.35.2 built from 1da5701 on 2021-01-11T02:54:03Z
Config file
$ cat .golangci.yml
no config
Go environment
$ go version 
go version go1.15.6 darwin/amd64

Consider the following minimal example:

package main

import "fmt"

type user struct {
	name string
	age  int
}

func main() {
	fmt.Println(getHello())

	u := &user{name: "John Doe"}
	fmt.Println(u)
}

func getHello() string {
	return fmt.Sprintf("Hallo")
}

Running staticcheck . finds the following problems:

main.go:7:2: field age is unused (U1000)
main.go:18:9: unnecessary use of fmt.Sprintf (S1039)

Running golangci-lint run --disable-all --enable staticcheck -v. doesn't output any issues:

INFO [config_reader] Config search paths: XXX
INFO [lintersdb] Active 1 linters: [staticcheck]
INFO [loader] Go packages loading at mode 575 (compiled_files|files|imports|name|types_sizes|deps|exports_file) took 214.13809ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 168.483µs
INFO [linters context/goanalysis] analyzers took 0s with no stages
INFO [runner] processing took 5.779µs with stages: max_same_issues: 1.726µs, nolint: 1.454µs, filename_unadjuster: 418ns, skip_dirs: 259ns, cgo: 184ns, skip_files: 180ns, identifier_marker: 175ns, max_from_linter: 171ns, severity-rules: 125ns, exclude: 123ns, autogenerated_exclude: 120ns, path_prefixer: 118ns, uniq_by_line: 117ns, source_code: 117ns, path_prettifier: 114ns, diff: 112ns, path_shortener: 108ns, max_per_file_from_linter: 55ns, sort_results: 54ns, exclude-rules: 49ns
INFO [runner] linters took 21.253215ms with stages: staticcheck: 21.097502ms
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 4 samples, avg is 73.2MB, max is 73.6MB
INFO Execution took 252.932387ms

It exits with status code 0, i.e. it doesn't find any issues with the code.

@marten-seemann marten-seemann added the bug Something isn't working label Jan 13, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Jan 13, 2021

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez
Copy link
Member

ldez commented Jan 13, 2021

$ golangci-lint run
cmd/foo.go:7:2: `age` is unused (structcheck)
        age  int
        ^
cmd/foo.go:18:9: S1039: unnecessary use of fmt.Sprintf (gosimple)
        return fmt.Sprintf("Hallo")
               ^

staticcheck is in fact split into different parts: gosimple, unused, stylecheck, staticcheck.

@marten-seemann
Copy link
Author

Should it be removed from the list of linters then, or replaced by an error / warning telling the user exactly which linters it was split up into? Running golangci-lint run --disable-all --enable staticcheck and not getting any errors is pretty confusing in my opinion.

@ldez ldez changed the title staticcheck not working Confusing staticcheck rule activation Feb 13, 2021
@ldez ldez added enhancement New feature or improvement and removed bug Something isn't working labels Apr 29, 2021
@ldez ldez added this to the v2.0.0 milestone Apr 29, 2021
@ldez ldez removed this from the v2.0.0 milestone May 17, 2021
@ldez
Copy link
Member

ldez commented May 17, 2021

More explanation about staticcheck configuration in: #1989 (comment)

Closed in favor of #357

@ldez ldez closed this as completed May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants