Skip to content

emptyStringTest: handle len(s) > 0 #1392

@rprtr258

Description

@rprtr258

sample code

package main

import "fmt"

func main() {
        s := ""
        if len(s) == 0 { fmt.Println("len(s) == 0") }
        if len(s) != 0 { fmt.Println("len(s) != 0") }
        if len(s) > 0 { fmt.Println("len(s) > 0") }
}

gocritic check -enableAll main.go gives only

./main.go:8:5: emptyStringTest: replace `len(s) != 0` with `s != ""`
./main.go:7:5: emptyStringTest: replace `len(s) == 0` with `s == ""`

and no complaints to replace len(s) > 0 with s != ""

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions