test: Add a check for too long or badly reflowed docstrings
This ensures that docstring comments are wrapped to 80 chars. ffrank seemed to be making this mistake far too often, and it's a silly thing to look for manually. As it turns out, I've made it too, as have many others. Now we have a test that checks for most cases. There are still a few stray cases that aren't checked automatically, but this can be improved upon if someone is motivated to do so. Before anyone complains about the 80 character limit: this only checks docstring comments, not source code length or inline source code comments. There's no excuse for having docstrings that are badly reflowed or over 80 chars, particularly if you have an automated test.
This commit is contained in:
@@ -35,8 +35,7 @@ func init() {
|
||||
// Format returns returns a textual representation of the input time. The format
|
||||
// has to be defined like specified by the golang "time" package. The time is
|
||||
// the number of seconds since the epoch, and matches what comes from our Now
|
||||
// function.
|
||||
// Golang documentation: https://golang.org/pkg/time/#Time.Format
|
||||
// function. Golang documentation: https://golang.org/pkg/time/#Time.Format
|
||||
func Format(input []types.Value) (types.Value, error) {
|
||||
epochDelta := input[0].Int()
|
||||
if epochDelta < 0 {
|
||||
|
||||
@@ -67,8 +67,8 @@ func (obj *PrintfFunc) ArgGen(index int) (string, error) {
|
||||
// Polymorphisms returns the possible type signature for this function. In this
|
||||
// case, since the number of arguments can be infinite, it returns the final
|
||||
// precise type if it can be gleamed from the format argument. If it cannot, it
|
||||
// is because either the format argument was not known statically, or because
|
||||
// it had an invalid format string.
|
||||
// is because either the format argument was not known statically, or because it
|
||||
// had an invalid format string.
|
||||
func (obj *PrintfFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error) {
|
||||
if partialType == nil || len(partialValues) < 1 {
|
||||
return nil, fmt.Errorf("first argument must be a static format string")
|
||||
|
||||
@@ -31,8 +31,8 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// Split splits the input string using the separator and returns the
|
||||
// segments as a list.
|
||||
// Split splits the input string using the separator and returns the segments as
|
||||
// a list.
|
||||
func Split(input []types.Value) (types.Value, error) {
|
||||
str, sep := input[0].Str(), input[1].Str()
|
||||
|
||||
|
||||
@@ -66,8 +66,8 @@ func (obj *CPUCountFact) Init(init *facts.Init) error {
|
||||
}
|
||||
|
||||
// Stream returns the changing values that this fact has over time. It will
|
||||
// first poll sysfs to get the initial cpu count, and then receives UEvents
|
||||
// from the kernel as CPUs are added/removed.
|
||||
// first poll sysfs to get the initial cpu count, and then receives UEvents from
|
||||
// the kernel as CPUs are added/removed.
|
||||
func (obj CPUCountFact) Stream() error {
|
||||
defer close(obj.init.Output) // signal when we're done
|
||||
|
||||
@@ -178,8 +178,8 @@ func getCPUCount() (int64, error) {
|
||||
return parseCPUList(string(dat))
|
||||
}
|
||||
|
||||
// Parses a line of the form X,Y,Z,... where X,Y,Z can be either a single CPU or a
|
||||
// contiguous range of CPUs. e.g. "2,4-31,32-63". If there is an error parsing
|
||||
// Parses a line of the form X,Y,Z,... where X,Y,Z can be either a single CPU or
|
||||
// a contiguous range of CPUs. e.g. "2,4-31,32-63". If there is an error parsing
|
||||
// the line the function will return 0.
|
||||
func parseCPUList(list string) (int64, error) {
|
||||
var count int64
|
||||
|
||||
@@ -44,14 +44,16 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// GetEnv gets environment variable by name or returns empty string if non existing.
|
||||
// GetEnv gets environment variable by name or returns empty string if non
|
||||
// existing.
|
||||
func GetEnv(input []types.Value) (types.Value, error) {
|
||||
return &types.StrValue{
|
||||
V: os.Getenv(input[0].Str()),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DefaultEnv gets environment variable by name or returns default if non existing.
|
||||
// DefaultEnv gets environment variable by name or returns default if non
|
||||
// existing.
|
||||
func DefaultEnv(input []types.Value) (types.Value, error) {
|
||||
value, exists := os.LookupEnv(input[0].Str())
|
||||
if !exists {
|
||||
|
||||
@@ -86,9 +86,9 @@ func (obj *TemplateFunc) ArgGen(index int) (string, error) {
|
||||
// case, since the second argument can be an infinite number of values, it
|
||||
// instead returns either the final precise type (if it can be gleamed from the
|
||||
// input partials) or if it cannot, it returns a single entry with the complete
|
||||
// type but with the variable second argument specified as a `variant` type.
|
||||
// If it encounters any partial type specifications which are not possible, then
|
||||
// it errors out. This could happen if you specified a non string template arg.
|
||||
// type but with the variable second argument specified as a `variant` type. If
|
||||
// it encounters any partial type specifications which are not possible, then it
|
||||
// errors out. This could happen if you specified a non string template arg.
|
||||
// XXX: is there a better API than returning a buried `variant` type?
|
||||
func (obj *TemplateFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error) {
|
||||
// TODO: return `variant` as second arg for now -- maybe there's a better way?
|
||||
|
||||
@@ -131,7 +131,8 @@ type Engine struct {
|
||||
// Init initializes the struct. This is the first call you must make. Do not
|
||||
// proceed with calls to other methods unless this succeeds first. This also
|
||||
// loads all the functions by calling Init on each one in the graph.
|
||||
// TODO: should Init take the graph as an input arg to keep it as a private field?
|
||||
// TODO: should Init take the graph as an input arg to keep it as a private
|
||||
// field?
|
||||
func (obj *Engine) Init() error {
|
||||
obj.ag = make(chan error)
|
||||
obj.agLock = &sync.Mutex{}
|
||||
|
||||
@@ -61,8 +61,8 @@ type Info struct {
|
||||
Err error // did this fact validate?
|
||||
}
|
||||
|
||||
// Init is the structure of values and references which is passed into all
|
||||
// facts on initialization.
|
||||
// Init is the structure of values and references which is passed into all facts
|
||||
// on initialization.
|
||||
type Init struct {
|
||||
Hostname string // uuid for the host
|
||||
//Noop bool
|
||||
|
||||
@@ -149,7 +149,8 @@ func (obj *function) MakeGoReturn() (string, error) {
|
||||
return obj.Return[0].ToGolang()
|
||||
}
|
||||
|
||||
// ConvertStart returns the start of a casting function required to convert from mcl to golang.
|
||||
// ConvertStart returns the start of a casting function required to convert from
|
||||
// mcl to golang.
|
||||
func (obj *function) ConvertStart() string {
|
||||
t := obj.Return[0].Type
|
||||
switch t {
|
||||
@@ -162,7 +163,8 @@ func (obj *function) ConvertStart() string {
|
||||
}
|
||||
}
|
||||
|
||||
// ConvertStop returns the end of the conversion function required to convert from mcl to golang.
|
||||
// ConvertStop returns the end of the conversion function required to convert
|
||||
// from mcl to golang.
|
||||
func (obj *function) ConvertStop() string {
|
||||
t := obj.Return[0].Type
|
||||
switch t {
|
||||
|
||||
Reference in New Issue
Block a user