pedroMMM/goss

View on GitHub
add.go

Summary

Maintainability
C
1 day
Test Coverage

Function AddResource has 95 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func AddResource(fileName string, gossConfig GossConfig, resourceName, key string, config util.Config, sys *system.System) error {
    // Need to figure out a good way to refactor this
    switch resourceName {
    case "Addr":
        res, err := gossConfig.Addrs.AppendSysResource(key, sys, config)
Severity: Major
Found in add.go - About 2 hrs to fix

    Function AddResource has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
    Open

    func AddResource(fileName string, gossConfig GossConfig, resourceName, key string, config util.Config, sys *system.System) error {
        // Need to figure out a good way to refactor this
        switch resourceName {
        case "Addr":
            res, err := gossConfig.Addrs.AppendSysResource(key, sys, config)
    Severity: Minor
    Found in add.go - About 2 hrs to fix

    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

    Function AutoAddResource has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
    Open

    func AutoAddResource(fileName string, gossConfig GossConfig, key string, sys *system.System) error {
        // file
        if strings.Contains(key, "/") {
            if res, _, ok := gossConfig.Files.AppendSysResourceIfExists(key, sys); ok == true {
                resourcePrint(fileName, res)
    Severity: Minor
    Found in add.go - About 1 hr to fix

    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

    Function AddResource has 16 return statements (exceeds 4 allowed).
    Open

    func AddResource(fileName string, gossConfig GossConfig, resourceName, key string, config util.Config, sys *system.System) error {
        // Need to figure out a good way to refactor this
        switch resourceName {
        case "Addr":
            res, err := gossConfig.Addrs.AppendSysResource(key, sys, config)
    Severity: Major
    Found in add.go - About 1 hr to fix

      Function AddResource has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      func AddResource(fileName string, gossConfig GossConfig, resourceName, key string, config util.Config, sys *system.System) error {
      Severity: Minor
      Found in add.go - About 35 mins to fix

        2: cannot find package "github.com/aelsabbahy/goss/system" in any of:
        Open

            "github.com/aelsabbahy/goss/system"
        Severity: Minor
        Found in add.go by govet

        comment on exported function AutoAddResources should be of the form "AutoAddResources ..."
        Open

        // Simple wrapper to add multiple resources
        Severity: Minor
        Found in add.go by golint

        exported function AddResource should have comment or be unexported
        Open

        func AddResource(fileName string, gossConfig GossConfig, resourceName, key string, config util.Config, sys *system.System) error {
        Severity: Minor
        Found in add.go by golint

        comment on exported function AddResources should be of the form "AddResources ..."
        Open

        // Simple wrapper to add multiple resources
        Severity: Minor
        Found in add.go by golint

        exported function AutoAddResource should have comment or be unexported
        Open

        func AutoAddResource(fileName string, gossConfig GossConfig, key string, sys *system.System) error {
        Severity: Minor
        Found in add.go by golint

        There are no issues that match your filters.

        Category
        Status