-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
"lint:ignore" comments are ignored by staticcheck #741
Comments
Couple notes here, because I just hit this:
|
I also faced this problem. Well, a better workaround would be disabling |
I guess we incorrectly configure |
Any progress here? Facing the same issue but do not want to disable the checks completely in the project. |
Seems it's introduced by #699 |
From https://golangci-lint.run/usage/false-positives/ + some experiments, you have to do this now: package main
import (
"fmt"
"time"
)
func main() {
//nolint:staticcheck // SA1004 ignore this!
time.Sleep(1)
fmt.Println("hello")
} |
@simonpasquier This would be disabling staticcheck at all, not only the SA1004 of staticcheck. |
@simonpasquier can this be re-opened? I don't believe using |
This PR fixed golangci-lint violations in status_manager_test.go which would make all PR fail on the current CI. I'm ignoring staticcheck on that file rather than ignoring only the specific SA1019 as per this [1] issue on golangci-lint. [1] golangci/golangci-lint#741
I would also like to see this revisited. I have the following code (or similar) in a few places due to imported protobuf definitions that use the older Go protobuf API version:
I like to use both staticcheck standalone and golangci-lint, and I don't believe disabling staticcheck entirely for the file is a great workaround. Has there been any determination on why these directives are ignored when staticcheck is called from within golangci-lint? |
This should work package main
import (
"fmt"
"time"
)
func main() {
//lint:ignore SA1004 ingore this for now
time.Sleep(1)
fmt.Println("hello")
} |
Against what version? Definitely not working for me. |
I couldn't get it to work out of the box as well. My need was to ignore a certain directive just in certain files as a whole and neither using The only way I could work around it was by adding the exclude rule I wanted in the Here is an example that worked to ignore a single directive in a certain file: issues:
exclude-rules:
- path: path/to/your/file/your_file.go
linters:
- staticcheck
text: SA1019 |
This bug is not fixed; can it please be re-opened? When I run staticcheck standalone against my code, it correctly ignores lines annotated with The workarounds posted above are incomplete: using the one posted by uloureiro disables the given check for the entire file, not just the single line; the one posted simonpasquier disables all staticcheck checks for that line, not just the single check. The example posted by NYARAS should work, but it does not: that's the whole point of this issue. Please re-open and investigate why golangci-lint causes staticcheck to not respect its own |
Same, still fails here. @simonpasquier would you mind reopening? |
I will try to provide a better overview.
Inside golangci-lint we use the sets of rules, not the binary. The We recommend using the https://golangci-lint.run/usage/false-positives/ ExamplesExclude the rule globally: linters:
disable-all: true
enable:
- staticcheck
linters-settings:
staticcheck:
checks:
- all
- '-SA1019' Exclude the rule globally for specific method: linters:
disable-all: true
enable:
- staticcheck
issues:
exclude:
- 'SA1019: http.CloseNotifier' Exclude the rule globally for specific method: linters:
disable-all: true
enable:
- staticcheck
issues:
exclude-rules:
- linters:
- staticcheck
text: 'SA1019: http.CloseNotifier' Exclude the rule in a file for specific method: linters:
disable-all: true
enable:
- staticcheck
issues:
exclude-rules:
- path: ^main.go
text: 'SA1019: http.CloseNotifier' Exclude the linter in a file for a specific line: package main
import (
"net/http"
)
func main() {
//nolint:staticcheck // I want to use deprecated method.
var to http.CloseNotifier
_ = to
} |
after my work got delayed by this issue, I finally passed the Jenkins CI/CD build by creating a linters:
enable:
- misspell
- typecheck
- etc...
issues:
exclude:
- ^G104
exclude-rules:
- linters:
- staticcheck
text: "SA1019:" I exclude the path because I want to ignore all //lint:ignore SA1019 Ignore the deprecation warnings
ok, err := yourDeprecatedMethod(input) finally 🚀 |
…868) * implements futures functions and GRPC functions on new branch * lint and test fixes * Fix uneven split pnl. Adds collateral weight test. docs. New clear func * Test protection if someone has zero collateral * Uses string instead of double for accuracy * Fixes old code panic * context, match, docs * Addresses Shazniterinos, var names, expanded tests * Returns subaccount name, provides USD values when offlinecalc * Fixes oopsie * Fixes cool bug which allowed made up subaccount results * Subaccount override on FTX, subaccount results for collateral * Strenghten collateral account info checks. Improve FTX test * English is my first language * Fixes oopsies * Fixes for unrealised PNL & collateral rendering * Fixes lint and tests * Shaznit fixes * Secret Shaznit * Updates account information across wrappers to include more fields * Updates online collateral calculations. Updates RPC data * Accurately calculates collateral offline and online minus testing * Tests and lint chocolate * Simplifies accountinfo results * Fixes shaznits * Adds new func * Increases collateral accuracy again again again x 200 * Increases accuracy of collateral rendering * Fixes minor merge/test issues * Linterino * Fixes ws test. Improves collateral calculations and rendering * Make it prettier * Removes the lock I put on 👀 * Adds `additional_collateral_used` field, renders orig currency * Fixes unrelated test * Fix test * Correctly calculate spot margin borrow collateral * Address fun lint surprise See golangci/golangci-lint#741 (comment) * Strange lint fixing x2 * Continued lint journey * Nolint the nolint to not lint the lint * Adds two new fields to response * More linting issues arising * fIX3s_c4s|NG * Fixes command flags' incorrect numbering * FairMarket = Won
I bet you didn't try my solution: #741 (comment). |
Hi @denisvmedia I did see your comment but I didn't quite understand it to be honest. So to clarify, your suggestion is to avoid using staticcheck via golangci-lint and to just use it directly, is that right? If so then I guess that is possible to do as it looks like null-ls (which I also use) has a builtin for staticcheck https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/lua/null-ls/builtins/diagnostics/staticcheck.lua UPDATE: So I went and disabled staticcheck via my golangci-lint Next, I renabled staticcheck via golangci-lint (just to see if maybe any of the code comment solutions for ignoring the error would now suddenly work) but found that golangci-lint didn't seem to be running staticcheck at all. So I decided to run golangci-lint directly (as opposed to running it via Neovim) and it seems to think staticcheck is an active linter but didn't report any issues? So either there were no issues to report, which I don't believe because of the issue with the code as shown in my screenshot from earlier, or staticcheck just wasn't being run by golangci-lint. I then ran So why was Neovim reporting a staticcheck issue when configured via gopls but not via golangci-lint or directly via staticcheck? I then manually wrote some bad code that I knew staticcheck would fail on, and when running staticcheck directly it would report an issue (👍🏻) but interestingly, when running golangci-lint directly, it again would still not report anything from staticcheck? But it would show part of an issue because of revive (which golangci-lint) is also configured to use...
So I was then in this weird situation where running At this point I checked in the golang repo and noticed this comment, which seems to explain the behaviour...
I did not know there was a difference between running the binary vs importing its code. So there's likely more to ignoring issues than I first realised due to how staticcheck is being invoked/executed. Later on in the same Go reported GitHub issue someone stated that yes you can't ignore errors using line directives when importing the staticcheck analyzers and that only works when invoking the staticcheck binary! So I then installed null-ls' staticcheck and found that again it doesn't report the issue from my screenshot because it's invoking the binary, unlike gopls which imports the staticcheck analyzers and clearly they behave differently. But anything that the staticcheck binary reports as an issue I can ignore using So for me I'm going to keep |
Not mentioned above. Here is a quick solution to eliminate the error itself on
|
Solution for deprecated packages without
|
This comment was marked as abuse.
This comment was marked as abuse.
I already provided all the information here: #741 (comment) This issue was about Golangci-lint provides This issue was closed by the original author because he found a solution (the usage of About the deprecated packages: Without `nolint` directive on the importspackage main
import (
"fmt"
"golang.org/x/crypto/openpgp"
)
func main() {
fmt.Println(openpgp.SignatureType)
} $ golangci-lint version
golangci-lint has version 1.55.2 built with go1.21.3 from e3c2265f on 2023-11-03T12:59:25Z
$ golangci-lint run --no-config --enable-all=false --enable=staticcheck
main.go:6:2: SA1019: "golang.org/x/crypto/openpgp" is deprecated: this package is unmaintained except for security fixes. New applications should consider a more focused, modern alternative to OpenPGP for their specific task. If you are required to interoperate with OpenPGP systems and need a maintained package, consider a community fork. See https://golang.org/issue/44226. (staticcheck)
"golang.org/x/crypto/openpgp"
^ With `nolint` directive on the importspackage main
//nolint:staticcheck
import (
"fmt"
"golang.org/x/crypto/openpgp"
)
func main() {
fmt.Println(openpgp.SignatureType)
} $ golangci-lint version
golangci-lint has version 1.55.2 built with go1.21.3 from e3c2265f on 2023-11-03T12:59:25Z
$ golangci-lint run --no-config --enable-all=false --enable=staticcheck
$ As you can see the directive |
@ldez ah my bad, that linked comment didn't make it clear to me that the comment functionality was fixed. It seemed as if it was only fixed from editing a yaml file. |
…e file from the troublesome linter (see golangci/golangci-lint#741)
…e file from the troublesome linter (see golangci/golangci-lint#741)
…e file from the troublesome linter (see golangci/golangci-lint#741)
It seems that golangci-lint v1.19.0 ignores
//lint:ignore
comments. Tested with this very simple program:golangci-lint v1.19.0 fails with:
golangci-lint v1.18.0 succeeds as well as staticcheck 2019.2.3.
System information
golangci-lint has version 1.19.0 built from 27ac4c7 on 2019-09-23T20:40:17Z
The text was updated successfully, but these errors were encountered: