Generated go.sum and proto file detection

This commit is contained in:
Lauris BH 2022-07-18 15:08:20 +03:00
parent ed2adad159
commit fe195c67a9
No known key found for this signature in database
GPG Key ID: DFDE60A0093EB926

View File

@ -96,6 +96,9 @@ var GeneratedCodeNameMatchers = []GeneratedCodeNameMatcher{
// Poetry lock // Poetry lock
nameEndsWith("poetry.lock"), nameEndsWith("poetry.lock"),
// go mod sum file
nameEndsWith("go.sum"),
} }
// GeneratedCodeMatcher checks whether the file with the given data is // GeneratedCodeMatcher checks whether the file with the given data is
@ -113,6 +116,7 @@ var GeneratedCodeMatchers = []GeneratedCodeMatcher{
isGeneratedJavaScriptPEGParser, isGeneratedJavaScriptPEGParser,
isGeneratedPostScript, isGeneratedPostScript,
isGeneratedGo, isGeneratedGo,
isGeneratedProtobufFromGo,
isGeneratedProtobuf, isGeneratedProtobuf,
isGeneratedJavaScriptProtocolBuffer, isGeneratedJavaScriptProtocolBuffer,
isGeneratedApacheThrift, isGeneratedApacheThrift,
@ -339,6 +343,24 @@ func isGeneratedGo(_, ext string, content []byte) bool {
return false return false
} }
func isGeneratedProtobufFromGo(_, ext string, content []byte) bool {
if ext != ".proto" {
return false
}
lines := getLines(content, 20)
if len(lines) <= 1 {
return false
}
for _, line := range lines {
if bytes.Contains(line, []byte("This file was autogenerated by go-to-protobuf")) {
return true
}
}
return false
}
var protoExtensions = map[string]struct{}{ var protoExtensions = map[string]struct{}{
".py": {}, ".py": {},
".java": {}, ".java": {},