Skip to content

Commit

Permalink
feat: exclude Swagger Codegen files (#4967)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Sep 4, 2024
1 parent 0275389 commit a6bd868
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/result/processors/autogenerated_exclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions pkg/result/processors/autogenerated_exclude_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a6bd868

Please sign in to comment.