zephinzer/dev

View on GitHub

Showing 69 of 79 total issues

Similar blocks of code found in 5 locations. Consider refactoring.
Open

package open

import (
    "github.com/spf13/cobra"
    "github.com/zephinzer/dev/cmd/dev/open/merge_request"
Severity: Major
Found in cmd/dev/open/command.go and 4 other locations - About 1 hr to fix
cmd/dev/get/github/command.go on lines 1..22
cmd/dev/get/gitlab/command.go on lines 1..22
cmd/dev/get/pivotaltracker/command.go on lines 1..22
cmd/dev/get/trello/command.go on lines 1..22

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 151.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function run has 57 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func run(command *cobra.Command, args []string) {
    targetWorkspaceName := strings.Join(args, ".")
    if len(targetWorkspaceName) == 0 {
        command.Help()
        workspaces := c.Global.Repositories.GetWorkspaces()
Severity: Minor
Found in cmd/dev/get/workspace/command.go - About 1 hr to fix

    Function GetCommand has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
    Open

    func GetCommand() *cobra.Command {
        cmd := cobra.Command{
            Use:     constants.AccountCanonicalNoun,
            Aliases: constants.AccountAliases,
            Short:   "Retrieves account information from Trello",
    Severity: Minor
    Found in cmd/dev/get/trello/account/command.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

    Method TodoSerializer.GetMessage has 55 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (ts TodoSerializer) GetMessage() string {
        targetType := ts.getTargetType()
        createdAt := humanize.Time(ts.CreatedAt)
        switch ts.ActionName {
        case "assigned":
    Severity: Minor
    Found in internal/gitlab/todos.go - About 1 hr to fix

      Function WatchNotifications has 55 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func WatchNotifications(
          accessToken string,
          fromProjects Projects,
          databaseConnection *sql.DB,
          updateInterval time.Duration,
      Severity: Minor
      Found in internal/pivotaltracker/watchers.go - About 1 hr to fix

        Function run has 54 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func run(cmd *cobra.Command, args []string) {
            pathToInitialiseAt := path.Join(args...)
            log.Debug("resolving provided path %s...", pathToInitialiseAt)
            pathToInitialiseAt, resolvePathError := utils.ResolvePath(pathToInitialiseAt)
            if resolvePathError != nil {
        Severity: Minor
        Found in cmd/dev/initialise/repository/command.go - About 1 hr to fix

          Function Download has 11 return statements (exceeds 4 allowed).
          Open

          func Download(options DownloadOptions) error {
              downloadStatus := DownloadStatus{}
              tmpFilePath := options.FilePath + ".download_" + time.Now().Format("20060102150405")
              if options.Events == nil {
                  options.Events = make(chan DownloadEvent, 16)
          Severity: Major
          Found in pkg/utils/network/download.go - About 1 hr to fix

            Function GetCommand has 52 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func GetCommand() *cobra.Command {
                cmd := cobra.Command{
                    Use:     constants.NotificationsCanonicalNoun,
                    Aliases: constants.NotificationsAliases,
                    Short:   "Initialises telegram notifications",
            Severity: Minor
            Found in cmd/dev/initialise/telegram/notifications/command.go - About 1 hr to fix

              Function Init has 10 return statements (exceeds 4 allowed).
              Open

              func Init(atPath string) error {
                  directory := filepath.Dir(atPath)
                  filename := filepath.Base(atPath)
                  fullPath := path.Join(directory, filename)
                  fullPathInfo, checkFileError := os.Lstat(fullPath)
              Severity: Major
              Found in internal/db/init.go - About 1 hr to fix

                Function Unzip has 10 return statements (exceeds 4 allowed).
                Open

                func Unzip(options UnzipOptions) []error {
                    var err error
                    status := UnzipStatus{}
                
                    if options.Events == nil {
                Severity: Major
                Found in pkg/utils/unzip.go - About 1 hr to fix

                  Function run has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func run(command *cobra.Command, args []string) {
                      if config.Global.Repositories == nil {
                          log.Error("no repositories have been defined")
                          os.Exit(1)
                          return
                  Severity: Minor
                  Found in cmd/dev/check/repositories/command.go - About 55 mins 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 run has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func run(command *cobra.Command, args []string) {
                      if len(args) == 0 {
                          command.Help()
                          log.Errorf("no repository url(s) specified, see usage above for how to use this command")
                          os.Exit(1)
                  Severity: Minor
                  Found in cmd/dev/add/repository/command.go - About 55 mins 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 GetSSH has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func GetSSH(keysDirectory string) ([]Key, error) {
                      directoryList, readDirError := ioutil.ReadDir(keysDirectory)
                      if readDirError != nil {
                          return nil, fmt.Errorf("failed to list directory at '%s': %s", keysDirectory, readDirError)
                      }
                  Severity: Minor
                  Found in pkg/utils/keys/ssh_keys.go - About 55 mins 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 Untar has 9 return statements (exceeds 4 allowed).
                  Open

                  func Untar(options UntarOptions) []error {
                      var err error
                      status := UntarStatus{}
                  
                      if options.Events == nil {
                  Severity: Major
                  Found in pkg/utils/untar.go - About 55 mins to fix

                    Function run has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func run(command *cobra.Command, args []string) {
                        targetWorkspaceName := strings.Join(args, ".")
                        if len(targetWorkspaceName) == 0 {
                            command.Help()
                            workspaces := c.Global.Repositories.GetWorkspaces()
                    Severity: Minor
                    Found in cmd/dev/get/workspace/command.go - About 55 mins 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 getOAuthCallbackHandler has 8 return statements (exceeds 4 allowed).
                    Open

                    func getOAuthCallbackHandler(res http.ResponseWriter, req *http.Request) {
                        requestID := uuid.New().String()
                    
                        params := mux.Vars(req)
                    
                    
                    Severity: Major
                    Found in cmd/dev/start/server/get_oauth_callback.go - About 50 mins to fix

                      Function WatchNotifications has 7 return statements (exceeds 4 allowed).
                      Open

                      func WatchNotifications(
                          accounts []AccountConfig,
                          databaseConnection *sql.DB,
                          updateInterval time.Duration,
                          stop chan struct{},
                      Severity: Major
                      Found in internal/gitlab/watchers.go - About 45 mins to fix

                        Method Repository.GetPath has 7 return statements (exceeds 4 allowed).
                        Open

                        func (r Repository) GetPath(rootPath ...string) (string, error) {
                            // if :rootPath is defined, use that as the root instead of the current directory
                            storagePath := "."
                            if len(rootPath) > 0 {
                                storagePath = rootPath[0]
                        Severity: Major
                        Found in pkg/repository/repository.go - About 45 mins to fix

                          Method VSCode.WriteTo has 7 return statements (exceeds 4 allowed).
                          Open

                          func (vsc VSCode) WriteTo(workspacePath string, overwrite ...bool) error {
                              isOverwritable := false
                              if len(overwrite) > 0 {
                                  isOverwritable = overwrite[0]
                              }
                          Severity: Major
                          Found in internal/workspace/vscode.go - About 45 mins to fix

                            Function Check has 7 return statements (exceeds 4 allowed).
                            Open

                            func Check(atPath string) error {
                                absolutePath, resolvePathError := utils.ResolvePath(atPath)
                                if resolvePathError != nil {
                                    return fmt.Errorf("failed to resolve path '%s': %s", atPath, resolvePathError)
                                }
                            Severity: Major
                            Found in internal/db/check.go - About 45 mins to fix
                              Severity
                              Category
                              Status
                              Source
                              Language