-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
improve the heuristics to detect commented out code #230
Comments
What are you seeing exactly? Gofumpt will not add any spaces to the code you showed as of the latest master version, and the latest stable version is the same.
|
package main
import "fmt"
func main() {
pwet := true
fmt.Printf("%b", pwet)
if pwet {
//fmt.Printf("%b", pwet)
return
}
}
diff --git main.go main.go
index 8f26369..22084d7 100644
--- main.go
+++ main.go
@@ -6,7 +6,7 @@ func main() {
pwet := true
fmt.Printf("%b", pwet)
if pwet {
- //fmt.Printf("%b", pwet)
+ // fmt.Printf("%b", pwet)
return
}
} |
The heuristic is at Lines 415 to 419 in 8f1392a
In your case, there is just one comment and it doesn't match our heuristic - which is currently "is the first character special?". I guess one way to make the heuristic a bit more clever is to also treat a comment line as code if it parses as a valid Go statement or declaration. That's not particularly easy to do unfortunately, given that https://pkg.go.dev/go/parser only allows parsing files or expressions, but it is doable. |
Follow up of #6 (comment)
I like to make a distinction between comments and commented code, i.e.:
This way I can grep for commented code without having comments returned and vice versa.
Regards.
The text was updated successfully, but these errors were encountered: