禁用针对“复合文字使用无键字段”的兽医检查

问题描述 投票:22回答:3

我正在运行我的CI工具上的vet,并开始收到错误:

composite literal uses unkeyed fields

因为我在实例化

type A struct {
   *B
}

像这样:

A{b} // b is of type *B

我不关心这个警告,并希望在我的兽医检查中禁用它。我该怎么做呢?

go warnings suppress-warnings
3个回答
22
投票
$ go doc cmd/vet

默认情况下,执行所有检查。如果任何标志显式设置为true,则仅运行那些测试。相反,如果任何标志显式设置为false,则仅禁用那些测试。因此-printf = true运行printf检查,-printf = false运行除printf检查之外的所有检查。

Unkeyed composite literals

Flag: -composites

Composite struct literals that do not use the field-keyed syntax.

45
投票

您可以禁用它,也可以修改代码:

a := A{B: b}

playground


2
投票
go tool vet -composites=false .
© www.soinside.com 2019 - 2024. All rights reserved.