dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.24k stars 377 forks source link

quickfix QF1013: detect quoted string escaping quote, while backticks could be used #1566

Open ccoVeille opened 5 months ago

ccoVeille commented 5 months ago

I didn't find a linter for this so I'm creating an issue here.

I asked Gopher Slack community https://gophers.slack.com/archives/C4MTR76PQ/p1719215628975379

And it appears I was right and this linter/checker doesn't exist yet.

The idea is to be able to report this for any string

fmt.Println("I'm \"happy\"")
fmt.Println(`I'm "happy"`)

This should be an optional rule of course, as it could bring a lot of noise.

I think one could improve the readability of the code

ccoVeille commented 5 months ago

@dominikh suggested adapting https://github.com/dominikh/go-tools/blob/master/simple/s1007/s1007.go on Gopher Slack

ccoVeille commented 5 months ago

@dominikh how do we attribute a number for the checker I mean the sXXXX ?

dominikh commented 5 months ago

The prefix for quickfixes is QF, its only category is 1, so currently the next available ID would be QF1013.

ccoVeille commented 5 months ago

This could help me to list all strings wherever they are

https://github.com/dominikh/go-tools/blob/master/stylecheck%2Fst1018%2Fst1018.go

Antonboom commented 3 months ago

+1 to such check was surprised too that it doesn't implement yet anywhere