Showing 247 of 615 total issues
Function TestDiff
has 53 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestDiff(t *testing.T) {
t.Parallel()
src, err := ioutil.TempFile("", "unarchive_test.txt")
require.NoError(t, err)
Method Fetch.applyWithContext
has 53 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (f *Fetch) applyWithContext(context.Context) (resource.TaskStatus, error) {
var (
hsh hash.Hash
err error
status = resource.NewStatus()
Function TestAptInstallPackage
has 52 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestAptInstallPackage(t *testing.T) {
t.Parallel()
t.Run("when installed", func(t *testing.T) {
pkg := "foo1"
Function TestIsTrue
has 52 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestIsTrue(t *testing.T) {
t.Run("errors-when-unrendered", func(t *testing.T) {
g := sampleGraph()
meta, _ := g.Get("root/b")
_, err := conditional.IsTrue(meta)
Method Printer.FinishPP
has 52 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (p *Printer) FinishPP(g *graph.Graph) (pp.Renderable, error) {
tmpl, err := p.template(`{{if .Errors}}Errors:
{{range .Errors}} * {{.}}
{{end}}
{{end}}
Method Network.Apply
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (n *Network) Apply(context.Context) (resource.TaskStatus, error) {
status := resource.NewStatus()
var (
nw *dc.Network
Function TestDependencyResolverHandlesConditionalMetadata
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestDependencyResolverHandlesConditionalMetadata(t *testing.T) {
t.Parallel()
type test struct {
Value int
}
Function zipFiles
has 10 return statements (exceeds 4 allowed). Open
Open
func zipFiles(source, destination string) error {
base := ""
zipFile, err := os.Create(destination)
if err != nil {
Method Renderer.lookup
has 9 return statements (exceeds 4 allowed). Open
Open
func (r *Renderer) lookup(name string) (string, error) {
g := r.Graph()
// fully-qualified graph name
fqgn := graph.SiblingID(r.ID, name)
Method Preparer.Prepare
has 9 return statements (exceeds 4 allowed). Open
Open
func (p *Preparer) Prepare(ctx context.Context, render resource.Renderer) (resource.Task, error) {
if strings.TrimSpace(p.Source) == "" {
return nil, errors.New("\"source\" must contain a value")
}
Method User.Apply
has 9 return statements (exceeds 4 allowed). Open
Open
func (u *User) Apply(context.Context) (resource.TaskStatus, error) {
// lookup the user by name
// ErrUnsupported is returned if the system is not supported
// Lookup returns user.UnknownUserError if the user is not found
userByName, nameErr := u.system.Lookup(u.Username)
Method RPCProvider.VertexGetLabel
has 9 return statements (exceeds 4 allowed). Open
Open
func (p RPCProvider) VertexGetLabel(e graphviz.GraphEntity) (pp.VisibleRenderable, error) {
var name string
if e.Name == rootNodeID {
name = "/"
Method Printer.InitColors
has 9 return statements (exceeds 4 allowed). Open
Open
func (p *Printer) InitColors() {
reset := "\x1b[0m"
p.funcsMapWrite("bold", p.styled(func(in string) string { return "\x1b[1m" + in + reset }))
p.funcsMapWrite("black", p.styled(func(in string) string { return "\x1b[30m" + in + reset }))
p.funcsMapWrite("red", p.styled(func(in string) string { return "\x1b[31m" + in + reset }))
Method ExtendedTemplate.New
has 9 return statements (exceeds 4 allowed). Open
Open
func (tmpl *ExtendedTemplate) New(source string) (*template.Template, error) {
reset := "\x1b[0m"
funcs := map[string]interface{}{
// colors
"black": tmpl.styled(func(in string) string { return "\x1b[30m" + in + reset }),
Function loadKeyring
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
Open
func loadKeyring(ks *Keystore) (openpgp.KeyRing, error) {
var keyring openpgp.EntityList
trustedKeys := make(map[string]*openpgp.Entity)
for _, p := range []string{ks.SystemPath, ks.UserPath, ks.LocalPath} {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method Preparer.Prepare
has 9 return statements (exceeds 4 allowed). Open
Open
func (p *Preparer) Prepare(ctx context.Context, render resource.Renderer) (resource.Task, error) {
if strings.TrimSpace(p.Source) == "" {
return nil, errors.New("\"source\" must contain a value")
}
_, err := url.Parse(p.Source)
Method Preparer.getValueForField
has 8 return statements (exceeds 4 allowed). Open
Open
func (p *Preparer) getValueForField(r Renderer, field reflect.StructField) (reflect.Value, error) {
// get the field name for use in future lookups
name := p.getFieldName(field)
raw, isSet := p.Source[name]
Method Node.Validate
has 8 return statements (exceeds 4 allowed). Open
Open
func (n *Node) Validate() error {
if n == nil {
return errors.New("node is empty, check for bad input")
}
Method Unarchive.setDirsAndContents
has 8 return statements (exceeds 4 allowed). Open
Open
func (u *Unarchive) setDirsAndContents() (bool, error) {
var err error
// set the unarchive destination directory
u.destDir, err = os.Open(u.Destination)
Function ExportedFields
has 8 return statements (exceeds 4 allowed). Open
Open
func ExportedFields(input interface{}) (exported []*ExportedField, err error) {
nonEmbeddedFields := make(map[string]struct{})
embeddedFields := make(map[string][]*ExportedField)
if nil == input {
return exported, ErrNilStruct