go-critic / go-critic

The most opinionated Go source code linter for code audit.
https://go-critic.com
MIT License
1.86k stars 116 forks source link

commentedOutCode: false positive for the example output oneliner #1444

Open alexandear opened 1 week ago

alexandear commented 1 week ago

The following code in the file gocritic_test.go produces commentedOutCode false positive:

package env_test

import "fmt"

func ExampleCommentedOutCode() {
    const c = "{Foo:a}"
    fmt.Printf("%v", c)
    // Output: {Foo:a}
}
❯ gocritic check -enable commentedOutCode gocritic_test.go
./gocritic_test.go:8:2: commentedOutCode: may want to remove commented-out code

Found in the caarlos0/env repo:

❯ gocritic check -enable commentedOutCode example_test.go
./example_test.go:353:2: commentedOutCode: may want to remove commented-out code
./example_test.go:391:2: commentedOutCode: may want to remove commented-out code
quasilyte commented 1 week ago

The Output: prefix should be easy enough to recognize as we already have something like a list of "give up" words.