Skip to content

feat: exclude Swagger Codegen files #4967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading