Skip to content

false-positive: number used inside a mathematical operations #96

@ldez

Description

@ldez
package sandbox

import (
	"fmt"
	"net/http"
)

func Foo(resp *http.Response) {
	if resp.StatusCode/100 != 2 {
		fmt.Println("foo")
	}
	if resp.StatusCode+100 != 2 {
		fmt.Println("foo")
	}
	if resp.StatusCode-100 != 2 {
		fmt.Println("foo")
	}
	if resp.StatusCode*100 != 2 {
		fmt.Println("foo")
	}
}
$ ggolangci-lint run --enable-only usestdlibvars --max-same-issues 0
main.go:9:21: "100" can be replaced by http.StatusContinue (usestdlibvars)
--max-saif resp.StatusCode/100 != 2 {ount of issues with the same text. Set to 0 to disable
                           ^
main.go:12:21: "100" can be replaced by http.StatusContinue (usestdlibvars)
        if resp.StatusCode+100 != 2 {
                           ^
main.go:15:21: "100" can be replaced by http.StatusContinue (usestdlibvars)
        if resp.StatusCode-100 != 2 {
                           ^
main.go:18:21: "100" can be replaced by http.StatusContinue (usestdlibvars)
        if resp.StatusCode*100 != 2 {
                           ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions