Skip to content
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

Gitlint #51

Merged
merged 3 commits into from
Dec 10, 2022
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
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ func RootCmd() *cobra.Command {
func main() {
if err := RootCmd().Execute(); err != nil {
fmt.Println(err)
os.Exit(1) //nolint:revive
os.Exit(1)
}
}
18 changes: 9 additions & 9 deletions pkg/schemas/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func indexOf(a string, list []string) int {
return i
}
}
return -1 //nolint:revive
return -1
}

// Remove fields that is not related to taxonomy
Expand All @@ -276,18 +276,18 @@ func (context *GeneratorContext) removeExtraProps(typeIdent crd.TypeIdent, v *ap
}
// If the field is not in the list of the needed fields then remove it from the schema
_, fieldKnownInfo := context.parser.Types[typeIdentField]
if indexOf(typeIdentField.Name, fieldTypes) == -1 || !fieldKnownInfo { //nolint:revive
if indexOf(typeIdentField.Name, fieldTypes) == -1 || !fieldKnownInfo {
jsonTag, hasTag := field.Tag.Lookup("json")
if !hasTag {
continue
}
jsonOpts := strings.Split(jsonTag, ",")
delete(v.Properties, jsonOpts[0]) //nolint:revive
index := indexOf(jsonOpts[0], v.Required) //nolint:revive
if index != -1 { //nolint:revive
delete(v.Properties, jsonOpts[0])
index := indexOf(jsonOpts[0], v.Required)
if index != -1 {
length := len(v.Required)
v.Required[index] = v.Required[length-1] //nolint:revive
v.Required = v.Required[:length-1] //nolint:revive
v.Required[index] = v.Required[length-1]
v.Required = v.Required[:length-1]
}
}
}
Expand Down Expand Up @@ -350,7 +350,7 @@ func (context *GeneratorContext) definitionNameFor(documentName string, typeIden
// escapes).
func qualifiedName(pkgName, typeName string) string {
if pkgName != Empty {
return strings.Replace(pkgName, "/", "~1", -1) + "~0" + typeName //nolint:revive
return strings.Replace(pkgName, "/", "~1", -1) + "~0" + typeName
}
return typeName
}
Expand All @@ -367,7 +367,7 @@ func (context *GeneratorContext) TypeRefLink(from *loader.Package, to crd.TypeId
// the `schema` marker or in a package with a type that has the `object` marker
// Otherwise, the suffix will be build using qualifiedName function
suffix := to.Name
if indexOf(to.Package.PkgPath, context.objectPkgs) == -1 { //nolint:revive
if indexOf(to.Package.PkgPath, context.objectPkgs) == -1 {
suffix = context.definitionNameFor(toDocument, to)
}
return prefix + suffix
Expand Down
16 changes: 8 additions & 8 deletions pkg/schemas/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func mapToSchema(ctx *schemaContext, mapType *ast.MapType) *apiext.JSONSchemaPro
for keyInfo != nil {
switch typedKey := keyInfo.(type) {
case *types.Basic:
if typedKey.Info()&types.IsString == 0 { //nolint:revive
if typedKey.Info()&types.IsString == 0 {
ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("map keys must be strings, not %s", keyInfo.String()), mapType.Key))
return &apiext.JSONSchemaProps{}
}
Expand Down Expand Up @@ -358,22 +358,22 @@ func structToSchema(ctx *schemaContext, structType *ast.StructType) *apiext.JSON
continue
}
jsonOpts := strings.Split(jsonTag, ",")
if len(jsonOpts) == 1 && jsonOpts[0] == "-" { //nolint:revive
if len(jsonOpts) == 1 && jsonOpts[0] == "-" {
// skipped fields have the tag "-" (note that "-," means the field is named "-")
continue
}

inline := false
omitEmpty := false
for _, opt := range jsonOpts[1:] { //nolint:revive
for _, opt := range jsonOpts[1:] {
switch opt {
case "inline":
inline = true
case "omitempty":
omitEmpty = true
}
}
fieldName := jsonOpts[0] //nolint:revive
fieldName := jsonOpts[0]
inline = inline || fieldName == Empty // anonymous fields are inline fields in YAML/JSON

// if no default required mode is set, default to required
Expand Down Expand Up @@ -428,13 +428,13 @@ func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ, format st
// non-string types.
basicInfo := basic.Info()
switch {
case basicInfo&types.IsBoolean != 0: //nolint:revive
case basicInfo&types.IsBoolean != 0:
typ = "boolean"
case basicInfo&types.IsString != 0: //nolint:revive
case basicInfo&types.IsString != 0:
typ = "string"
case basicInfo&types.IsInteger != 0: //nolint:revive
case basicInfo&types.IsInteger != 0:
typ = "integer"
case basicInfo&types.IsFloat != 0: //nolint:revive
case basicInfo&types.IsFloat != 0:
if allowDangerousTypes {
typ = "number"
} else {
Expand Down