According to the source code for gorename
, the check is simple: It looks for a comment at the beginning of the line that contains the phrase "DO NOT EDIT":
// Matches cgo generated comment as well as the proposed standard:
// https://golang.org/s/generatedcode
var generatedRx = regexp.MustCompile(`// .*DO NOT EDIT\.?`)
// generated reports whether ast.File is a generated file.
func generated(f *ast.File, tokenFile *token.File) bool {
// Iterate over the comments in the file
for _, commentGroup := range f.Comments {
for _, comment := range commentGroup.List {
if matched := generatedRx.MatchString(comment.Text); matched {
// Check if comment is at the beginning of the line in source
if pos := tokenFile.Position(comment.Slash); pos.Column == 1 {
return true
}
}
}
}
return false
}
Reading elsewhere in the source code, where the error message itself is generated, it looks like the error message may simply be misleading:
// Renaming not supported if cgo files are affected.
var generatedFileNames []string
for _, info := range r.packages {
for _, f := range info.Files {
tokenFile := r.iprog.Fset.File(f.Pos())
if filesToUpdate[tokenFile] && generated(f, tokenFile) {
generatedFileNames = append(generatedFileNames, tokenFile.Name())
}
}
}
if !Force && len(generatedFileNames) > 0 {
return fmt.Errorf("refusing to modify generated file%s containing DO NOT EDIT marker: %v", plural(len(generatedFileNames)), generatedFileNames)
}
I see you are using CGO. It appears that this also triggers the "generated file" marker.