thriftlint/checks/optional.go
2017-01-11 15:39:49 +11:00

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
})
}