登录
首页 >  Golang >  Go问答

案例不足以展示 parsing.tokenType 类型的 golinter 切换

来源:stackoverflow

时间:2024-02-23 18:54:26 310浏览 收藏

一分耕耘,一分收获!既然都打开这篇《案例不足以展示 parsing.tokenType 类型的 golinter 切换》,就坚持看下去,学下去吧!本文主要会给大家讲到等等知识点,如果大家对本文有好的建议或者看到有不足之处,非常欢迎大家积极提出!在后续文章我会继续更新Golang相关的内容,希望对大家都有所帮助!

问题内容

所以我有这个代码

token := nexttoken()
switch token.typ {
case tokeneof:
    return nil
case tokenmentiontargetedcontrol:
    # do stuff
default:
    return nil
}

我的令牌类型是一个枚举

我的 golinter 抛出了这个错误:

missing cases in switch of type parsing.tokenType: parsing.tokenControl, parsing.tokenLinkControl, parsing.tokenMailtoControl, parsing.tokenMentionControl, parsing.tokenChannelControl, parsing.tokenText (exhaustive)

我不想为每个场景创建一个案例,因为我有默认子句,如何避免这种情况?


正确答案


exhaustive linter 具有 default-signizes-exhaustive 选项。将其设置为 true:

linters:
  enable:
    - exhaustive
linters-settings:
  exhaustive:
    # Presence of "default" case in switch statements satisfies exhaustiveness,
    # even if all enum members are not listed.
    # Default: false
    default-signifies-exhaustive: true

参见https://golangci-lint.run/usage/linters/#exhaustive.

今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>