MCPcopy Index your code
hub / github.com/docker/docker-agent / isConstructor

Function isConstructor

lint/constructor_purity.go:57–66  ·  view source on GitHub ↗

isConstructor reports whether fn is a plain top-level function named New or New (the next rune after "New" is upper-case) that returns at least one result.

(fn *ast.FuncDecl)

Source from the content-addressed store, hash-verified

55// New<Something> (the next rune after "New" is upper-case) that returns at
56// least one result.
57func isConstructor(fn *ast.FuncDecl) bool {
58 if fn.Recv != nil || fn.Name == nil {
59 return false
60 }
61 name := fn.Name.Name
62 if !isConstructorName(name) {
63 return false
64 }
65 return fn.Type.Results != nil && len(fn.Type.Results.List) > 0
66}
67
68func isConstructorName(name string) bool {
69 return name == "New" || (len(name) > 3 && name[:3] == "New" && name[3] >= 'A' && name[3] <= 'Z')

Calls 1

isConstructorNameFunction · 0.85

Tested by

no test coverage detected