grokify/mogo

View on GitHub

Showing 87 of 144 total issues

Avoid deeply nested control flow statements.
Open

    } else if valFloat, ok := v.(float64); ok {
        return valFloat != 0.0
    }
Severity: Major
Found in type/interfaceutil/interfaceutil.go - About 45 mins to fix

    Function ReadDirRxSubmatch has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
    Open

    func ReadDirRxSubmatch(dir string, rx *regexp.Regexp, subMatchIdx uint, inclDirs, inclFiles, inclEmptyFiles bool) (map[string][]os.DirEntry, error) {
        entryMap := map[string][]os.DirEntry{}
    
        entries, err := os.ReadDir(dir)
        if err != nil {
    Severity: Minor
    Found in os/osutil/dir.go - About 45 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

    Avoid deeply nested control flow statements.
    Open

                        if opts.InclusiveMatch {
                            matches = append(matches, tok)
                        }
    Severity: Major
    Found in html/htmlutil/tokenizer.go - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

          } else if req.BodyType == BodyTypeXML {
              return xmlutil.MarshalIndent(req.Body, "", "", req.AddXMLDocType)
          } else if req.BodyType == BodyTypeForm {
              if v, ok := req.Body.(url.Values); ok {
                  return []byte(v.Encode()), nil
      Severity: Major
      Found in net/http/httpsimple/simplerequest.go - About 45 mins to fix

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

        func Filenames(name string, rx *regexp.Regexp, inclEmptyFiles, absPath bool) ([]string, error) {
            isFile, err := IsFile(name, !inclEmptyFiles)
            if err != nil {
                return []string{}, err
            }
        Severity: Major
        Found in os/osutil/filepath.go - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

              } else if valFloat, ok := v.(float64); ok {
                  return int(valFloat)
              } else {
                  return defaultValue
              }
          Severity: Major
          Found in type/interfaceutil/interfaceutil.go - About 45 mins to fix

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

            func SeverityInclude(filterLevel, itemLevel string) (bool, error) {
                filterLevelGood, err := Parse(filterLevel)
                if err != nil || filterLevelGood == SeverityDisabled {
                    return false, err
                }
            Severity: Major
            Found in log/severity/severity.go - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                              } else if opts.IncludeChain {
                                  matches = append(matches, tok)
                              }
              Severity: Major
              Found in html/htmlutil/tokenizer.go - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                    } else if !stringsutil.UniqueRunes(a2) {
                        return errors.New("alphabet 2 chars are not unique")
                    }
                Severity: Major
                Found in encoding/basex/encoding.go - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if opts.InclusiveMatch {
                                          matches = append(matches, tok)
                                      }
                  Severity: Major
                  Found in html/htmlutil/tokenizer.go - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                            } else if units == "y" {
                                s = fmt.Sprintf("%vs", i*YearSeconds)
                            } else {
                                return zeroDuration, errors.New("timeutil.ParseDuration Parse Error")
                            }
                    Severity: Major
                    Found in time/timeutil/duration.go - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                          } else if bl, ok := a.(bool); ok {
                              if bl {
                                  *s = String("true")
                              } else {
                                  *s = String("false")
                      Severity: Major
                      Found in encoding/jsonutil/tolerant_reader_types.go - About 45 mins to fix

                        Function DT6sToString has 6 return statements (exceeds 4 allowed).
                        Open

                        func DT6sToString(startDT6, endDT6 int32, layout, presentText, prefixText, joinText, suffixText string) (string, error) {
                            if startDT6 <= 0 && endDT6 <= 0 {
                                return "", nil
                            }
                            startText, endText, err := DT6sToStrings(startDT6, endDT6, layout, presentText)
                        Severity: Major
                        Found in time/month/strconv.go - About 40 mins to fix

                          Consider simplifying this complex logical expression.
                          Open

                                  if !(inclExists && inclNotExists) &&
                                      ((!inclExists && exists) || (!inclNotExists && !exists)) {
                          Severity: Major
                          Found in path/filepathutil/filepathutil.go - About 40 mins to fix

                            Function AddFileToArchive has 6 return statements (exceeds 4 allowed).
                            Open

                            func AddFileToArchive(tw *tar.Writer, filename, archivename string) error {
                                // Open the file which will be written into the archive
                                file, err := os.Open(filename)
                                if err != nil {
                                    return err
                            Severity: Major
                            Found in archive/tarutil/writer.go - About 40 mins to fix

                              Function ToBool has 6 return statements (exceeds 4 allowed).
                              Open

                              func ToBool(v any) bool {
                                  if v == nil {
                                      return false
                                  } else if valBool, ok := v.(bool); ok {
                                      return valBool
                              Severity: Major
                              Found in type/interfaceutil/interfaceutil.go - About 40 mins to fix

                                Function AddFileToZip has 6 return statements (exceeds 4 allowed).
                                Open

                                func AddFileToZip(zipWriter *zip.Writer, filename string, removePaths bool) error {
                                    fileToZip, err := os.Open(filename)
                                    if err != nil {
                                        return err
                                    }
                                Severity: Major
                                Found in compress/ziputil/create_achive.go - About 40 mins to fix

                                  Consider simplifying this complex logical expression.
                                  Open

                                      if t.Before(tr.Min) || t.After(tr.Max) ||
                                          (!inclusiveMin && t.Equal(tr.Min)) ||
                                          (!inclusiveMax && t.Equal(tr.Max)) {
                                  Severity: Major
                                  Found in time/timeutil/time_range.go - About 40 mins to fix

                                    Function VisitFiles has 6 return statements (exceeds 4 allowed).
                                    Open

                                    func VisitFiles(name string, visitFunc func(dir string, info fs.FileInfo) error) error {
                                        fileInfo, err := os.Stat(name)
                                        if err != nil {
                                            return err
                                        }
                                    Severity: Major
                                    Found in os/osutil/dir.go - About 40 mins to fix

                                      Function DirRemoveAllChildren has 6 return statements (exceeds 4 allowed).
                                      Open

                                      func DirRemoveAllChildren(dir string) error {
                                          isDir, err := IsDir(dir)
                                          if err != nil {
                                              return err
                                          }
                                      Severity: Major
                                      Found in os/osutil/dir.go - About 40 mins to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language