golangci / misspell

Correct commonly misspelled English words in source files
MIT License
22 stars 10 forks source link

Variable name only replaced once #18

Closed silverwind closed 5 months ago

silverwind commented 5 months ago

Running with the -dict option and passing commiter,committer, I see the variable only got replaced once on the first occurence, instead of all occurences in go code. I think it should have replaced on line 248 too here:

Screenshot 2024-04-18 at 20 02 09

Is it expected?

Ref: https://github.com/go-gitea/gitea/pull/30573

ldez commented 5 months ago

First, it's not a new behavior.

I have a minimal reproducible example:

package temp

import (
    "fmt"
    "os"
)

func foo() {
    smoe, _ := os.Open("test") // Detected
    defer smoe.Close() // Not detected

    fmt.Println(smoe) // Detected
    fmt.Println(smoe.Name()) // Not detected
}
$ go run ./cmd/misspell ./temp
temp/temp.go:9:1: "smoe" is a misspelling of "some"
temp/temp.go:12:13: "smoe" is a misspelling of "some"
ldez commented 5 months ago

It's a side effect/false negative of the host parsing.

silverwind commented 5 months ago

Ah yes, then it's an existing bug that wasn't noticed so far.

ldez commented 5 months ago

This has been the same behavior for the past 8 years, the goal being to avoid false positives. Then those false negatives are expected.

ldez commented 5 months ago

I can improve a bit by following some basic domain name rules, but it's impossible to fully fix that without creating a regression.

silverwind commented 5 months ago

Fine with me, those cases are easy enough to correct manually.

ldez commented 5 months ago

I improved hostname detection as I explained before.

Now, defer smoe.Close() will be detected. But defer smoe.close() is still not detected.

I created a v0.5.1

As the problem cannot be fully fixed, I will close this issue.

silverwind commented 5 months ago

Thanks, I can confirm it new replaced these missing cases, even without having reset the diff :)