go linter for vscode? (as extension to highlight issues, not cli tool)
Hi, I am new at Go and wondering if there is an extension to warn me that I am expected to pass age to to Person struct all these kind of safety stuff. I did search but couldn't find. Theo successfully convinced me about type safety.
6 Replies
do you have the go for vscode extension? also just an fyi, the red squiggles are the result of a language server protocol (lsp), so if you’re googling around try using that. a linter is what you would use after the fact as a more wholesome automated code review
i have that extension, but it doesnt tell me that I should pass age too.
That's because you don't have to pass Age
If you don't initialize the value it automatically intializes to the type's default, in the case of
int
that's 0
As a general tip what I like to do is go to popular repositories for the language I want to use and look at their .vscode file
Here’s an example: https://github.com/coder/coder/blob/main/.vscode/extensions.json
GitHub
coder/.vscode/extensions.json at main · coder/coder
A tool that provisions remote development environments via Terraform - coder/coder
that's the thing. I want to force passing age value instead of checking whether it is 0 or not. And 0 doesnt tell me whether it is what user passed or what go decided as default in case of no value.
In that case your options are either to use pointers, which by default are
nil
, so you can check for nil, which is a bit cumbersome, or making a constructor function(Usually dubbed New
), it is a recurring topic/proposal for GoLang(See here for example: https://github.com/golang/go/issues/28348)GitHub
Issues · golang/go
The Go programming language. Contribute to golang/go development by creating an account on GitHub.