Showing 98 of 159 total issues
Function MergeFilterCSVFilesToJSONL
has 10 return statements (exceeds 4 allowed). Open
Open
func MergeFilterCSVFilesToJSONL(inPaths []string, outPath string, inComma rune, andFilter map[string]stringsutil.MatchInfo) error {
outFh, err := os.Create(outPath)
if err != nil {
return err
}
Function ResizePathJPEGDir
has 9 return statements (exceeds 4 allowed). Open
Open
func ResizePathJPEGDir(src, out string, x, y uint, o *JPEGEncodeOptions) error {
if src == "" {
return ErrSrcDirNotDefined
} else if out == "" {
return ErrOutDirNotDefined
Function outputConstants
has 9 return statements (exceeds 4 allowed). Open
Open
func outputConstants(filename string, currs currencyutil.Currencies) error {
set, err := currencyutil.NewCurrencySet(currs...)
if err != nil {
return err
}
Function ToInt
has 8 return statements (exceeds 4 allowed). Open
Open
func ToInt(v any, defaultValue int) int {
if v == nil {
return defaultValue
} else if valBool, ok := v.(bool); ok {
if valBool {
Function BuildBinsDuration
has 8 return statements (exceeds 4 allowed). Open
Open
func BuildBinsDuration(d, extLeft, extRight time.Duration) Bins {
if extLeft == extRight {
if d < extRight {
return BuildBinsDurationLeftRight(d, extRight)
} else {
Method Request.BodyBytes
has 7 return statements (exceeds 4 allowed). Open
Open
func (req *Request) BodyBytes() ([]byte, error) {
if req.Body == nil {
return []byte{}, nil
} else if reqBodyBytes, ok := req.Body.([]byte); ok {
return reqBodyBytes, nil
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
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 valFloat != 0.0
}
Avoid deeply nested control flow statements. Open
Open
} else if valFloat, ok := v.(float64); ok {
return int(valFloat)
} else {
return defaultValue
}
Avoid deeply nested control flow statements. Open
Open
} else if endDd.MatchLeft(tok, nil) {
curDesc.Description = append(curDesc.Description, tok)
dl = append(dl, curDesc)
matching = ""
curDesc = Description{}
Avoid deeply nested control flow statements. Open
Open
if opts.InclusiveMatch {
matches = append(matches, tok)
}
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 extLeft != nil {
return BuildBinsDurationLeftRight(*extLeft, durs[0])
} else {
return BuildBinsDurationLeftRight(durs[0], *extRight)
}
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
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
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
} else if bl, ok := a.(bool); ok {
if bl {
*s = String("true")
} else {
*s = String("false")