golangci / misspell

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

Misspell corrected an imported constant's name. #10

Closed bnkamalesh closed 9 months ago

bnkamalesh commented 9 months ago

Misspell linter corrected a constant's name which was imported from a protobuff generated package. The problematic constant name Status_STATUS_CANCELLED, was corrected to a single L. This broke our CI as well, because autofix: true is the default setting.

Ref: https://github.com/microsoft/vscode/issues/200638 https://github.com/golang/vscode-go/issues/3087

Below I have provided the configuration of misspell.

  misspell:
    locale: US
    ignore-words:
      - cancelled // added this now as a work around

p.s: I added the respective word as a config under ignore-words as a work around.

ldez commented 9 months ago

Hello,

your issue is not clear: do you mean that ignore-words doesn't work?

bnkamalesh commented 9 months ago

Hello @ldez , thank you for the quick response and sorry for the confusion.

ignore-words is working as expected. The expected behaviour of misspell should only be correcting comments, but in this case it corrected a constant's name, which was imported from an external package.

ldez commented 9 months ago

The expected behaviour of misspell should only be correcting comments

I understand that can be surprising because it's a constant from another module but misspell checks all the code, neither just comments nor just code "own" by the current module, so the current behavior is expected.

The ignore-words is a solution but you can use different solutions based on exclusions like nolint.

func main() {
    //nolint:misspell
    fmt.Println(lib.Status_STATUS_CANCELLED)
}

https://golangci-lint.run/usage/false-positives/

bnkamalesh commented 9 months ago

Hello @ldez , I think there's some miscommunication if the expected behaviour of misspell is to correct any tokens. Because in the Readme it is mentioned explicitly

Are there special rules for golang source files? Yes! If the file ends in .go, then misspell will only check spelling in comments.

And it does make sense to have this behaviour as auto-correcting spellings of tokens would easily break our applications.

ldez commented 9 months ago

The misspell readme says something wrong: the scope of the analysis is not related to file extension but to a specific mode, and the default mode is neither related to Go nor file extension.

This mode is related to a CLI flag (-source) and the doc of this flag is also wrong and misleading. The doc of this flag says that there are 3 modes but, in the reality of the code, there are only 2: text (default) and go.

I also think that the go mode is misleading because it's not expected that a mode related to go only checks comments.

The current behavior of misspell inside golangci-lint is related to user's feedback (from 2019) https://github.com/golangci/golangci-lint/issues/522

EDIT: I fixed the documentation (readme and CLI flags) of misspell.

bnkamalesh commented 9 months ago

@ldez thanks for the clarification, and the quick responses are much appreciated. I'm closing the thread/issue as I believe it is solved.

ldez commented 9 months ago

@bnkamalesh I will add an option inside golangci-lint to handle the mode.

EDIT: https://github.com/golangci/golangci-lint/pull/4275