Skip to content

Goconst ignore-calls wrong behavior on v1.55.x #4240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
phith0n opened this issue Dec 6, 2023 · 6 comments · Fixed by #4555
Closed
5 tasks done

Goconst ignore-calls wrong behavior on v1.55.x #4240

phith0n opened this issue Dec 6, 2023 · 6 comments · Fixed by #4555
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@phith0n
Copy link

phith0n commented Dec 6, 2023

Welcome

Description of the problem

I found that the goconst setting ignore-calls has different behavior between 1.54.2 and 1.55.2, and not work as expection on v1.55.2.

My code:

package main

import (
	"net/http"
)

func main() {
	var token1 = "token1"
	var token2 = "token2"

	var request1 = http.Request{Header: make(http.Header)}
	request1.Header.Add("Authorization", "Bearer "+token1)

	var request2 = http.Request{Header: make(http.Header)}
	request2.Header.Add("Authorization", "Bearer "+token2)
}

There are two request2.Header.Add() functions to add "Authorization" headers to request.

Because I turn on the ignore-calls, I think there wounldn't be any error. It's indeed no error on the old version of golanglint-ci v1.54.2, but the v1.55.2 reports an error:

$ ./golangci-lint-v1.54.2 version
golangci-lint has version 1.54.2 built with go1.21.0 from 411e0bbb on 2023-08-21T12:04:32Z

$ ./golangci-lint-v1.54.2 run

$ ./golangci-lint-v1.55.2 version
golangci-lint has version 1.55.2 built with go1.21.3 from e3c2265f on 2023-11-03T12:59:25Z

$ ./golangci-lint-v1.55.2 run    
main.go:12:39: string `Bearer ` has 2 occurrences, make it a constant (goconst)
        request1.Header.Add("Authorization", "Bearer "+token1)
                                             ^

Version of golangci-lint

v1.55.2

Configuration

linters-settings:
  goconst:
    min-len: 2
    min-occurrences: 2
    ignore-calls: true
linters:
  disable-all: true
  enable:
    - goconst

run:
  timeout: 5m

Go environment

go version go1.21.5 linux/amd64

Verbose output of running

Output from v1.55.2:

$ ./golangci-lint-v1.55.2 version
golangci-lint has version 1.55.2 built with go1.21.3 from e3c2265f on 2023-11-03T12:59:25Z

$ ./golangci-lint-v1.55.2 run    
main.go:12:39: string `Bearer ` has 2 occurrences, make it a constant (goconst)
        request1.Header.Add("Authorization", "Bearer "+token1)
                                             ^

Output from v1.54.2:


$ ./golangci-lint-v1.54.2 version
golangci-lint has version 1.54.2 built with go1.21.0 from 411e0bbb on 2023-08-21T12:04:32Z

$ ./golangci-lint-v1.54.2 run

A minimal reproducible example or link to a public repository

package main

import (
	"net/http"
)

func main() {
	var token1 = "token1"
	var token2 = "token2"

	var request1 = http.Request{Header: make(http.Header)}
	request1.Header.Add("Authorization", "Bearer "+token1)

	var request2 = http.Request{Header: make(http.Header)}
	request2.Header.Add("Authorization", "Bearer "+token2)
}

Validation

  • Yes, I've included all information above (version, config, etc.).
@phith0n phith0n added the bug Something isn't working label Dec 6, 2023
Copy link

boring-cyborg bot commented Dec 6, 2023

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@phith0n phith0n changed the title Goconst ignore-calls different behaiver Goconst ignore-calls not work on v1.55.x Dec 6, 2023
@phith0n phith0n changed the title Goconst ignore-calls not work on v1.55.x Goconst ignore-calls wrong behaiver on v1.55.x Dec 6, 2023
@ldez ldez changed the title Goconst ignore-calls wrong behaiver on v1.55.x Goconst ignore-calls wrong behavior on v1.55.x Dec 6, 2023
@ldez
Copy link
Member

ldez commented Dec 6, 2023

Hello,

You checked the following box:

Have you tried to run goconst binary?

https://github.com/golangci/golangci-lint/blob/v1.54.2/go.mod#L54

https://github.com/golangci/golangci-lint/blob/v1.55.2/go.mod#L58

@ldez ldez added feedback required Requires additional feedback dependencies Relates to an upstream dependency labels Dec 6, 2023
@ldez
Copy link
Member

ldez commented Dec 6, 2023

It feels like a regression related to jgautheron/goconst#21

I recommend opening an issue on the goconst repository.

@ldez ldez removed the feedback required Requires additional feedback label Dec 6, 2023
@phith0n
Copy link
Author

phith0n commented Dec 6, 2023

I've tried goconst, but it doesn't have a ignore-calls option. The only way to set ignore-calls is to use golangci-lint, I don't know how can I open a issue for them...

@ldez
Copy link
Member

ldez commented Dec 6, 2023

It's not a golangci-lint bug, it's a goconst bug: we cannot handle the problem inside golangci-lint because it's inside the code of goconst.
You have to open an issue and explain the current situation.

@phith0n
Copy link
Author

phith0n commented Dec 6, 2023

It's not a golangci-lint bug, it's a goconst bug: we cannot handle the problem inside golangci-lint because it's inside the code of goconst. You have to open an issue and explain the current situation.

I see. Will raise a issue for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Relates to an upstream dependency
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants