mirror of
https://github.com/valitydev/thriftlint.git
synced 2024-11-06 00:05:20 +00:00
19 lines
544 B
Go
19 lines
544 B
Go
package checks
|
|
|
|
import (
|
|
"github.com/UrbanCompass/thriftlint"
|
|
|
|
"github.com/alecthomas/go-thrift/parser"
|
|
)
|
|
|
|
// CheckOptional ensures that all Thrift fields are optional, as is generally accepted best
|
|
// practice for Thrift.
|
|
func CheckOptional() thriftlint.Check {
|
|
return thriftlint.MakeCheck("optional", func(s *parser.Struct, f *parser.Field) (messages thriftlint.Messages) {
|
|
if f.Type.Name != "list" && f.Type.Name != "set" && f.Type.Name != "map" && !f.Optional {
|
|
messages.Warning(f, "%s must be optional", f.Name)
|
|
}
|
|
return
|
|
})
|
|
}
|