sách gpt4 ăn đã đi

golangci-lint 常量显式类型

In lại 作者:IT王子 更新时间:2023-10-29 01:51:47 37 4
mua khóa gpt4 giày nike

我有一个关于 golangci-lint 的问题。linter 返回我的东西是这样的:

type outputFormat string

hằng số (
formatNone outputFormat = ""
formatText = "TEXT"
formatJSON = "JSON"
)

错误如:

only the first constant in this group has an explicit type (staticcheck)
formatNone outputFormat = ""

但这有什么问题呢?在 https://go101.org/article/constants-and-variables.html他们在常量声明中的自动完成一章中描述了不完整的常量将被识别和填充。

我没有找到任何引用资料告诉我要避免使用不完整的常量定义。

谁能给我解释一下,这是怎么回事?

câu trả lời hay nhất

giống staticcheck 中所述的 documentation for that check :

In a constant declaration such as the following:

hằng số (
First byte = 1
Second = 2
)

the constant Thứ hai làm không have the same type as the constant First. This construct shouldn't be confused with

hằng số (
First byte = iota
Thứ hai
)

Ở đâu FirstThứ hai do indeed have the same type. The type is only passed on when no explicit value is assigned to the constant.

When declaring enumerations with explicit values it is therefore important not to write

hằng số (
EnumFirst EnumType = 1
EnumSecond = 2
EnumThird = 3
)

This discrepancy in types can cause various confusing behaviors and bugs.

关于golangci-lint 常量显式类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55282615/

37 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress