feat: exclude Swagger Codegen files (#4967)

This commit is contained in:
Ludovic Fernandez 2024-09-04 17:01:44 +02:00 committed by GitHub
parent 0275389a64
commit a6bd868cf0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -18,10 +18,19 @@ const (
AutogeneratedModeDisable = "disable"
)
// The values must be in lowercase.
const (
genCodeGenerated = "code generated"
genDoNotEdit = "do not edit"
genAutoFile = "autogenerated file" // easyjson
// Related to easyjson.
genAutoFile = "autogenerated file"
//nolint:lll // Long URL
// Related to Swagger Codegen.
// https://github.com/swagger-api/swagger-codegen/blob/61cfeac3b9d855b4eb8bffa0d118bece117bcb7d/modules/swagger-codegen/src/main/resources/go/partial_header.mustache#L16
// https://github.com/swagger-api/swagger-codegen/issues/12358
genSwaggerCodegen = "* generated by: swagger codegen "
)
var _ Processor = (*AutogeneratedExclude)(nil)
@ -101,7 +110,7 @@ func (p *AutogeneratedExclude) shouldPassIssue(issue *result.Issue) (bool, error
// The function uses a bit laxer rules than isGeneratedFileStrict to match more generated code.
// See https://github.com/golangci/golangci-lint/issues/48 and https://github.com/golangci/golangci-lint/issues/72.
func (p *AutogeneratedExclude) isGeneratedFileLax(doc string) bool {
markers := []string{genCodeGenerated, genDoNotEdit, genAutoFile}
markers := []string{genCodeGenerated, genDoNotEdit, genAutoFile, genSwaggerCodegen}
doc = strings.ToLower(doc)

View File

@ -42,6 +42,7 @@ func TestAutogeneratedExclude_isGeneratedFileLax_generated(t *testing.T) {
* THIS FILE SHOULD NOT BE EDITED BY HAND
*/`,
`// AUTOGENERATED FILE: easyjson file.go`,
` * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)`,
}
for _, comment := range comments {