Disable go vet checks for “composite literal uses unkeyed fields”

后端 未结 5 1567
醉酒成梦
醉酒成梦 2021-02-04 01:13

I\'m running go vet on my CI tool, and started getting the error:

composite literal uses unkeyed fields

Because I\'m instantiating



        
相关标签:
5条回答
  • 2021-02-04 01:16

    If you are using VS code, you have to manually set the flag under settings

    settings > Extensions > Go

    Scroll down to "Vet Flags" section

    Add Item and add the flag

    -composites=false .
    

    Click ok.

    Save one of your files again or restart VS code to see the effect.

    0 讨论(0)
  • 2021-02-04 01:17
    $ 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.
    
    0 讨论(0)
  • 2021-02-04 01:19
    go tool vet -composites=false .
    
    0 讨论(0)
  • 2021-02-04 01:23

    You can disable it or you can fix the code instead:

    a := A{B: b}
    

    playground

    0 讨论(0)
  • 2021-02-04 01:26

    You can disable it with the -composites=false flag: e.g.,

    go vet -composites=false .
    

    NB: go tool vet is deprecated

    0 讨论(0)
提交回复
热议问题