Showing 87 of 144 total issues
Avoid deeply nested control flow statements. Open
Open
} else if valFloat, ok := v.(float64); ok {
return valFloat != 0.0
}
Function ReadDirRxSubmatch
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
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 {
- 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
Avoid deeply nested control flow statements. Open
Open
if opts.InclusiveMatch {
matches = append(matches, tok)
}
Avoid deeply nested control flow statements. Open
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
Function Filenames
has 7 return statements (exceeds 4 allowed). Open
Open
func Filenames(name string, rx *regexp.Regexp, inclEmptyFiles, absPath bool) ([]string, error) {
isFile, err := IsFile(name, !inclEmptyFiles)
if err != nil {
return []string{}, err
}
Avoid deeply nested control flow statements. Open
Open
} else if valFloat, ok := v.(float64); ok {
return int(valFloat)
} else {
return defaultValue
}
Function SeverityInclude
has 7 return statements (exceeds 4 allowed). Open
Open
func SeverityInclude(filterLevel, itemLevel string) (bool, error) {
filterLevelGood, err := Parse(filterLevel)
if err != nil || filterLevelGood == SeverityDisabled {
return false, err
}
Avoid deeply nested control flow statements. Open
Open
} else if opts.IncludeChain {
matches = append(matches, tok)
}
Avoid deeply nested control flow statements. Open
Open
} else if !stringsutil.UniqueRunes(a2) {
return errors.New("alphabet 2 chars are not unique")
}
Avoid deeply nested control flow statements. Open
Open
if opts.InclusiveMatch {
matches = append(matches, tok)
}
Avoid deeply nested control flow statements. Open
Open
} else if units == "y" {
s = fmt.Sprintf("%vs", i*YearSeconds)
} else {
return zeroDuration, errors.New("timeutil.ParseDuration Parse Error")
}
Avoid deeply nested control flow statements. Open
Open
} else if bl, ok := a.(bool); ok {
if bl {
*s = String("true")
} else {
*s = String("false")
Function DT6sToString
has 6 return statements (exceeds 4 allowed). Open
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)
Consider simplifying this complex logical expression. Open
Open
if !(inclExists && inclNotExists) &&
((!inclExists && exists) || (!inclNotExists && !exists)) {
Function AddFileToArchive
has 6 return statements (exceeds 4 allowed). Open
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
Function ToBool
has 6 return statements (exceeds 4 allowed). Open
Open
func ToBool(v any) bool {
if v == nil {
return false
} else if valBool, ok := v.(bool); ok {
return valBool
Function AddFileToZip
has 6 return statements (exceeds 4 allowed). Open
Open
func AddFileToZip(zipWriter *zip.Writer, filename string, removePaths bool) error {
fileToZip, err := os.Open(filename)
if err != nil {
return err
}
Consider simplifying this complex logical expression. Open
Open
if t.Before(tr.Min) || t.After(tr.Max) ||
(!inclusiveMin && t.Equal(tr.Min)) ||
(!inclusiveMax && t.Equal(tr.Max)) {
Function VisitFiles
has 6 return statements (exceeds 4 allowed). Open
Open
func VisitFiles(name string, visitFunc func(dir string, info fs.FileInfo) error) error {
fileInfo, err := os.Stat(name)
if err != nil {
return err
}
Function DirRemoveAllChildren
has 6 return statements (exceeds 4 allowed). Open
Open
func DirRemoveAllChildren(dir string) error {
isDir, err := IsDir(dir)
if err != nil {
return err
}