Parse the output of deadcode and remove(rewrite) the dead code from the source files.
go install github.com/yyoshiki41/rdeadcode@latestdeadcode -json -test ./path/to/your/project | rdeadcodeor
rdeadcode -json deadcode.jsonPass the argument -file and -function to remove the dead code from the file.
rdeadcode -file path/to/your/file.go -function deadFunction$ rdeadcode -help
Usage of rdeadcode:
-json string
JSON file generated by deadcode
-file string
File to remove function from
-function string
Function to remove
-ignore string
Ignore files matching glob patternWarning
deadcode detects methods that implement an interface as dead code if it is not used in the project.
Please verify the interface compliance at compile time and restore the method when rdeadcode removes it.
// Verify interface compliance at compile time
var _ fmt.Stringer = myString{}
type myString struct {
Value string
}
func (s myString) String() string {
return s.Value
}