Disable go vet checks for "composite literal uses unkeyed fields"
Solution 1
$ go doc cmd/vet
By default all checks are performed. If any flags are explicitly set to true, only those tests are run. Conversely, if any flag is explicitly set to false, only those tests are disabled. Thus -printf=true runs the printf check, -printf=false runs all checks except the printf check.
Unkeyed composite literals Flag: -composites Composite struct literals that do not use the field-keyed syntax.
Solution 2
You can disable it or you can fix the code instead:
a := A{B: b}
Solution 3
If you're using the language server.
Gopls on by default in the VS Code Go extension
gopls
does vet check by default.
"gopls": {
"analyses": { "composites": false }
},
Solution 4
You can disable it with the -composites=false
flag: e.g.,
go vet -composites=false .
NB: go tool vet
is deprecated
Solution 5
go tool vet -composites=false .
Matt Joiner
About Me I like parsimonious code, with simple interfaces and excellent documentation. I'm not interested in enterprise, boiler-plate, or cookie-cutter nonsense. I oppose cruft and obfuscation. My favourite languages are Go, Python and C. I wish I was better at Haskell. Google+ GitHub Bitbucket Google code My favourite posts http://stackoverflow.com/questions/3609469/what-are-the-thread-limitations-when-working-on-linux-compared-to-processes-for/3705919#3705919 http://stackoverflow.com/questions/4352425/what-should-i-learn-first-before-heading-to-c/4352469#4352469 http://stackoverflow.com/questions/6167809/how-much-bad-can-be-done-using-register-variables-in-c/6168852#6168852 http://stackoverflow.com/questions/4141307/c-and-c-source-code-profiling-tools/4141345#4141345 http://stackoverflow.com/questions/3463207/how-big-can-a-malloc-be-in-c/3486163#3486163 http://stackoverflow.com/questions/4095637/memory-use-of-stl-data-structures-windows-vs-linux/4183178#4183178
Updated on July 09, 2022Comments
-
Matt Joiner almost 2 years
I'm running go vet on my CI tool, and started getting the error:
composite literal uses unkeyed fields
Because I'm instantiating
type A struct { *B }
like this:
A{b} // b is of type *B
I don't care for this warning, and want to disable it on my go vet checks. How do I do this?