Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.5k
New linter: Go responsewriter lint#3614
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Hey, thank you for opening your first Pull Request ! |
CLAassistant commentedFeb 18, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
|
56919e3 to17eb3fcComparejavorszky commentedFeb 18, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I'm having some issue running the tests that I can't seem to resolve, or even find the cause of: UPDATE: this was fixed by using the |
ldez commentedFeb 18, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
In order for a pull request adding a linter to be reviewed, the linter and the PR must follow some requirements. Pull Request Description
Linter
The Linter Tests Inside Golangci-lint
|
Uh oh!
There was an error while loading.Please reload this page.
Accepted suggestion.Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com>
alexandear commentedFeb 18, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Can someone explain to me whythis code generates the funcserveDepsJS(rw http.ResponseWriter,req*http.Request,dirstring) {...b,err:=closure.GenDeps(root)iferr!=nil {log.Print(err)http.Error(rw,"Server error",500)return}rw.Header().Set("Content-Type","text/javascript; charset=utf-8")rw.Write([]byte("// auto-generated from perkeepd\n"))rw.Write(b)} |
javorszky commentedFeb 19, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@alexandear I'm unsure which one is your question:
The PR itself has a link to the linter's own repository, where the readme has info on what it aims to do and why. I wrote it such that if I was in a situation where I wanted to find out what it's for, the readme would answer it. Let me know if you have additional questions. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
…sing itGood catch@leonklingele, thank you!Co-authored-by: leonklingele <git@leonklingele.de>
alexandear commentedFeb 19, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@javorszky, I apologize if my question comes across as rude - as a non-native speaker, I want to make sure I understand how this linter can be helpful in finding bugs. I'm checking the linter requirement What I did:
My understanding is that when you created the PR to add I am curious to know if you have analyzed any open-source projects with |
javorszky commentedFeb 19, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@alexandear that context makes a lot more sense, thank you. When I made the linter I followed this tutorial:https://disaev.me/p/writing-useful-go-analysis-linter/#run-on-the-real-and-large-repositories, and ran the linter on the Go source (1.19.2 at the time). That one did not flag up any issues. With false positives / negatives, I agree with you. In this case I don'treally count it as a false positive:
I wrote in the description that there are times when multiple calls or out of order calls to those methods are desirable. The purpose of this linter is to get developers to be purposeful in calling them out of order or multiple times. As an example, there's the |
The tests are what I used to validate the linter so that it triggers when I want it to, and does not trigger when I do not want it to. It's copy pasted from the linter's own repository. Tests there pass. Testing is written as per the tutorial. It seems like the way golangci-lint wraps the analysis tests is somewhat different. Does it bail on the first found issue? I would like some help with figuring out the differences between my own testing, and golangci-lint's way of doing it. |
Good point in adding instructions / blurb to installation methods. I do not have access to a Windows computer, but will do my best to accommodate users of other OSs. |
nightlyone commentedJun 2, 2023
Maybe the flagging of multiple successive Write calls should be made optional and default to off. That would allow zero false positives and still allow to enable that check. Multiple write calls are common in API responses that stream data and want to send out some initial data as soon as possible (e.g. a. CSV header in a CSV response). I would not like to flag all these in the future to make a linter happy. |
Uh oh!
There was an error while loading.Please reload this page.
Issue I see sometimes is that the order in which calls made to responsewriter end up with unexpected bug for those who don't have the side effects of calling
Write,WriteHeadermemorized in the http ResponseWriter interface.This linter should flag up potential places that might lead to bugs by finding calls that are in the wrong order, for example:
WriteHeadercalled afterWrite. By that time,Writehas already calledWriteHeaderwith anhttp.StatusOK, so additional call toWriteHeaderdoes nothingHeadercalled after eitherWriteorWriteHeader: headers are already sent, manipulating headers after that will take no effectWriteorWriteHeaderare probably not intended in the same function body, so those are also probably bugsLinter repository
https://github.com/javorszky/go-responsewriter-lint