Skip to content

Commit

Permalink
lint: gocritic (emtpyStringTest)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Sep 16, 2024
1 parent 92efb8a commit eb56406
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 24 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ linters-settings:
- appendCombine
- captLocal
- typeUnparen
- emptyStringTest #
- commentFormatting
- deferInLoop #
- sprintfQuotedString #
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/clialert/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func decisionsFromAlert(alert *models.Alert) string {
}

for _, key := range maptools.SortedKeys(decMap) {
if len(ret) > 0 {
if ret != "" {
ret += " "
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec/pour.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func runPour(input chan types.Event, holders []leaky.BucketFactory, buckets *lea
globalBucketPourKo.Inc()
}

if len(parsed.MarshaledTime) != 0 {
if parsed.MarshaledTime != "" {
if err := lastProcessedItem.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil {
log.Warningf("failed to unmarshal time from event : %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/acquisition/modules/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (cw *CloudwatchSource) UnmarshalConfig(yamlConfig []byte) error {
return fmt.Errorf("cannot parse CloudwatchSource configuration: %w", err)
}

if len(cw.Config.GroupName) == 0 {
if cw.Config.GroupName == "" {
return errors.New("group_name is mandatory for CloudwatchSource")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/acquisition/modules/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (d *DockerSource) EvalContainer(container dockerTypes.Container) *Container

for _, containerName := range d.Config.ContainerName {
for _, name := range container.Names {
if strings.HasPrefix(name, "/") && len(name) > 0 {
if strings.HasPrefix(name, "/") && name != "" {
name = name[1:]
}
if name == containerName {
Expand Down
6 changes: 3 additions & 3 deletions pkg/acquisition/modules/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (f *FileSource) UnmarshalConfig(yamlConfig []byte) error {
f.logger.Tracef("FileAcquisition configuration: %+v", f.config)
}

if len(f.config.Filename) != 0 {
if f.config.Filename != "" {
f.config.Filenames = append(f.config.Filenames, f.config.Filename)
}

Expand Down Expand Up @@ -202,11 +202,11 @@ func (f *FileSource) ConfigureByDSN(dsn string, labels map[string]string, logger

args := strings.Split(dsn, "?")

if len(args[0]) == 0 {
if args[0] == "" {
return errors.New("empty file:// DSN")
}

if len(args) == 2 && len(args[1]) != 0 {
if len(args) == 2 && args[1] != "" {
params, err := url.ParseQuery(args[1])
if err != nil {
return fmt.Errorf("could not parse file args: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/acquisition/modules/journalctl/journalctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (j *JournalCtlSource) ConfigureByDSN(dsn string, labels map[string]string,
}

qs := strings.TrimPrefix(dsn, "journalctl://")
if len(qs) == 0 {
if qs == "" {
return errors.New("empty journalctl:// DSN")
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/acquisition/modules/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,11 @@ func (s *S3Source) ConfigureByDSN(dsn string, labels map[string]string, logger *
})
dsn = strings.TrimPrefix(dsn, "s3://")
args := strings.Split(dsn, "?")
if len(args[0]) == 0 {
if args[0] == "" {
return errors.New("empty s3:// DSN")
}

if len(args) == 2 && len(args[1]) != 0 {
if len(args) == 2 && args[1] != "" {
params, err := url.ParseQuery(args[1])
if err != nil {
return fmt.Errorf("could not parse s3 args: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/apiclient/resperr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (e *ErrorResponse) Error() string {
message := ptr.OrEmpty(e.Message)
errors := ""

if len(e.Errors) > 0 {
if e.Errors != "" {
errors = fmt.Sprintf(" (%s)", e.Errors)
}

Expand Down Expand Up @@ -51,7 +51,7 @@ func CheckResponse(r *http.Response) error {
// try to unmarshal and if there are no 'message' or 'errors' fields, display the body as is,
// the API is following a different convention
err := json.Unmarshal(data, ret)
if err != nil || (ret.Message == nil && len(ret.Errors) == 0) {
if err != nil || (ret.Message == nil && ret.Errors == "") {
ret.Message = ptr.Of(fmt.Sprintf("http code %d, response: %s", r.StatusCode, string(data)))
return ret
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func ParseDuration(d string) (time.Duration, error) {

if strings.HasSuffix(d, "d") {
days := strings.Split(d, "d")[0]
if len(days) == 0 {
if days == "" {
return 0, fmt.Errorf("'%s' can't be parsed as duration", d)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/dumps/parser_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,23 @@ func (t *tree) displayResults(opts DumpOpts) {
}

if updated > 0 {
if len(changeStr) > 0 {
if changeStr != "" {
changeStr += " "
}

changeStr += yellow(fmt.Sprintf("~%d", updated))
}

if deleted > 0 {
if len(changeStr) > 0 {
if changeStr != "" {
changeStr += " "
}

changeStr += red(fmt.Sprintf("-%d", deleted))
}

if whitelisted {
if len(changeStr) > 0 {
if changeStr != "" {
changeStr += " "
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/exprhelpers/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type OpOutput struct {
func (o *OpOutput) String() string {

ret := fmt.Sprintf("%*c", o.CodeDepth, ' ')
if len(o.Code) != 0 {
if o.Code != "" {
ret += fmt.Sprintf("[%s]", o.Code)
}
ret += " "
Expand All @@ -70,7 +70,7 @@ func (o *OpOutput) String() string {
indent = 0
}
ret = fmt.Sprintf("%*cBLOCK_END [%s]", indent, ' ', o.Code)
if len(o.StrConditionResult) > 0 {
if o.StrConditionResult != "" {
ret += fmt.Sprintf(" -> %s", o.StrConditionResult)
}
return ret
Expand Down
2 changes: 1 addition & 1 deletion pkg/exprhelpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func FileInit(fileFolder string, filename string, fileType string) error {
if strings.HasPrefix(scanner.Text(), "#") { // allow comments
continue
}
if len(scanner.Text()) == 0 { //skip empty lines
if scanner.Text() == "" { //skip empty lines
continue
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/hubtest/nucleirunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (nc *NucleiConfig) RunNucleiTemplate(testName string, templatePath string,
log.Warningf("Stderr saved to %s", outputPrefix+"_stderr.txt")
log.Warningf("Nuclei generated output saved to %s", outputPrefix+".json")
return err
} else if len(out.String()) == 0 {
} else if out.String() != "" {
log.Warningf("Stdout saved to %s", outputPrefix+"_stdout.txt")
log.Warningf("Stderr saved to %s", outputPrefix+"_stderr.txt")
log.Warningf("Nuclei generated output saved to %s", outputPrefix+".json")
Expand Down
4 changes: 2 additions & 2 deletions pkg/longpollclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (c *LongPollClient) poll() error {

logger.Tracef("got response: %+v", pollResp)

if len(pollResp.ErrorMessage) > 0 {
if pollResp.ErrorMessage != "" {
if pollResp.ErrorMessage == timeoutMessage {
logger.Debugf("got timeout message")
return nil
Expand Down Expand Up @@ -209,7 +209,7 @@ func (c *LongPollClient) PullOnce(since time.Time) ([]Event, error) {

c.logger.Tracef("got response: %+v", pollResp)

if len(pollResp.ErrorMessage) > 0 {
if pollResp.ErrorMessage != "" {
if pollResp.ErrorMessage == timeoutMessage {
c.logger.Debugf("got timeout message")
break
Expand Down
2 changes: 1 addition & 1 deletion pkg/setup/units.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func systemdUnitList() ([]string, error) {

for scanner.Scan() {
line := scanner.Text()
if len(line) == 0 {
if line != "" {
break // the rest of the output is footer
}

Expand Down

0 comments on commit eb56406

Please sign in to comment.