Closed zak-pawel closed 12 months ago
I would enable this checker.
What is your plan with the current findings then? Are these all going to become additional ignore statements?
Take for example, one of x509 examples:
san := append(cert.DNSNames, cert.EmailAddresses...)
for _, ip := range cert.IPAddresses {
san = append(san, ip.String())
}
for _, uri := range cert.URIs {
san = append(san, uri.String())
}
tags["san"] = strings.Join(san, ",")
The append in this case is used to combine multiple string slices and additional strings into one to create a tag.
I see the purpose of this one to catch typos during development, but once merged I would expect every instance of this to be a valid usage and turn into yet another ignore.
@powersj I believe that all of them should be fixed. Not only to satisfy linter ;) but also to be sure that there is no common underlying array: https://freshman.tech/snippets/go/concatenate-slices/
The linter is finding when a slice is not assigned to the same slice in the first place. So let me ask again, how are you planning on resolving this linter.
edit: for example, are you planning on creating a new slice for every instance that all the other dump into?
Having looked at the first (main
) and fail2ban case as well as the x509 above, I come to the conclusion that at least those occurrences are false-positives. having something like myTempParams := append(someCommonParameterSet , someUseCaseSpecifcParameterSet...)
IS a valid use-case.
I'm closing this as something we won't take.
The primary thing this linter seems to look for is that the resulting slice is not the same as the first argument. After going through the above instances of this linter, they are generally false positives. In the tests for example, we combine two different arrays into an "expected" array, or want a specific order of merging two arrays into one new array.
Keeping the more verbose, new value names, adds clarity and intention to what the code is meant to do.
Description
This issue starts a discussion about enabling:
Example
Before:
After:
Expected output
Decision about enabling or not enabling this checker.
Findings
For this checker, the following findings were found in the current codebase:
Additional configuration
For this checker, no additional configuration can be provided.