Skip to content

Commit 5b5a00f

Browse files
ernadoclaude
andcommitted
build(lint): add union exhaustiveness checks, migrate golangci config to v2
- Migrate .golangci.yml to the v2 schema (the installed golangci-lint is v2; the old v1 config no longer loaded). Move gofmt/goimports to formatters, drop linters removed in v2 (maligned, scopelint, stylecheck, govet check-shadowing). - Enable exhaustive (typed enum switches) and gochecksumtype (sealed-interface unions) so non-exhaustive switches over ChatID/ReplyMarkup/ChatMember/etc. fail lint. - Reorder ReplyMarkup marker methods after their type defs (gocritic), fix a misspelling, and silence the noisy gosec G115 on known-safe conversions. Lint is green (0 issues). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7ab1acd commit 5b5a00f

3 files changed

Lines changed: 92 additions & 108 deletions

File tree

.golangci.yml

Lines changed: 86 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,105 @@
1-
linters-settings:
2-
revive:
3-
rules:
4-
- name: unused-parameter
5-
disabled: true
6-
- name: if-return
7-
disabled: true
8-
govet:
9-
check-shadowing: true
10-
gocyclo:
11-
min-complexity: 15
12-
maligned:
13-
suggest-new: true
14-
dupl:
15-
threshold: 120
16-
goconst:
17-
min-len: 2
18-
min-occurrences: 3
19-
misspell:
20-
locale: US
21-
lll:
22-
line-length: 140
23-
goimports:
24-
local-prefixes: github.com/gotd/botapi
25-
gocritic:
26-
enabled-tags:
27-
- diagnostic
28-
- experimental
29-
- opinionated
30-
- performance
31-
- style
32-
disabled-checks:
33-
- hugeParam
34-
- rangeValCopy
35-
- exitAfterDefer
36-
- whyNoLint
37-
- singleCaseSwitch
38-
- commentedOutCode
1+
version: "2"
392

403
linters:
41-
disable-all: true
4+
default: none
425
enable:
436
- dogsled
44-
# False positive: botapi has a lot of similar unimplemented methods
45-
# - dupl
467
- errcheck
8+
# Exhaustiveness of switches over typed enums (ParseMode, ChatType, ...).
9+
- exhaustive
10+
# Exhaustiveness of switches over sealed-interface unions (ChatID,
11+
# ReplyMarkup, ChatMember, ...). These are the "sum types" of this package:
12+
# interfaces with an unexported marker method.
13+
- gochecksumtype
4714
- gochecknoinits
4815
- goconst
4916
- gocritic
50-
- gofmt
51-
- goimports
5217
- revive
5318
- gosec
5419
- govet
5520
- ineffassign
5621
- lll
5722
- misspell
5823
- nakedret
59-
- typecheck
6024
- unconvert
6125
- unparam
6226
- whitespace
27+
settings:
28+
revive:
29+
rules:
30+
- name: unused-parameter
31+
disabled: true
32+
- name: if-return
33+
disabled: true
34+
govet:
35+
enable:
36+
- shadow
37+
goconst:
38+
min-len: 2
39+
min-occurrences: 3
40+
misspell:
41+
locale: US
42+
lll:
43+
line-length: 140
44+
exhaustive:
45+
# A `default:` case counts as covering the remaining variants.
46+
default-signifies-exhaustive: true
47+
gochecksumtype:
48+
# A `default:` case counts as covering the remaining variants.
49+
default-signifies-exhaustive: true
50+
gocritic:
51+
enabled-tags:
52+
- diagnostic
53+
- experimental
54+
- opinionated
55+
- performance
56+
- style
57+
disabled-checks:
58+
- hugeParam
59+
- rangeValCopy
60+
- exitAfterDefer
61+
- whyNoLint
62+
- singleCaseSwitch
63+
- commentedOutCode
64+
exclusions:
65+
rules:
66+
- linters: [gocritic]
67+
text: "commentedOutCode"
68+
source: "SHA1"
69+
# Allow embed globals.
70+
- source: "embed\\.FS"
71+
linters: [gochecknoglobals]
72+
# Exclude go:generate from lll.
73+
- source: "//go:generate"
74+
linters: [lll]
75+
# Relax noisy linters in tests.
76+
- path: _test\.go
77+
linters:
78+
- errcheck
79+
- gosec
80+
- goconst
81+
- lll
82+
# Ignore shadowing of common names.
83+
- linters: [govet]
84+
text: 'declaration of "(err|ctx|log)"'
85+
- path: internal\.go
86+
text: "should have.+comment"
87+
linters: [revive]
88+
# Allow underscores in package names.
89+
- linters: [revive]
90+
text: "underscores? in package names?"
91+
- linters: [staticcheck]
92+
text: "SA1019: (telegram|client).+ is deprecated:"
93+
# G115 (integer overflow on conversion) is noisy on known-safe size/index
94+
# conversions in storage and doc parsing.
95+
- linters: [gosec]
96+
text: "G115:"
6397

64-
# Do not enable:
65-
# - wsl (too opinionated about newlines)
66-
# - godox (todos are OK)
67-
# - bodyclose (false positives on helper functions)
68-
# - prealloc (not worth it in scope of this project)
69-
# - maligned (same as prealloc)
70-
# - funlen (gocyclo is enough)
71-
# - gochecknoglobals
72-
# - gocognit
73-
issues:
74-
exclude-use-default: false
75-
exclude-rules:
76-
- linters: [gocritic]
77-
text: "commentedOutCode"
78-
source: "SHA1"
79-
80-
# Allow embed globals
81-
- source: "embed\\.FS"
82-
linters: [gochecknoglobals]
83-
84-
# Exclude go:generate from lll
85-
- source: "//go:generate"
86-
linters: [lll]
87-
88-
# Disable linters that are annoying in tests.
89-
- path: _test\.go
90-
linters:
91-
- gocyclo
92-
- errcheck
93-
- dupl
94-
- gosec
95-
- funlen
96-
- goconst
97-
- gocognit
98-
- scopelint
99-
- lll
100-
- gochecknoglobals
101-
# Ignore shadowing of err.
102-
- linters: [govet]
103-
text: 'declaration of "(err|ctx|log)"'
104-
105-
- path: internal\.go
106-
text: "should have.+comment"
107-
linters: [revive]
108-
109-
# Allow underscores in package names.
110-
- linters: [revive, stylecheck]
111-
text: "underscores? in package names?"
112-
113-
- linters: [staticcheck]
114-
text: "SA1019: (telegram|client).+ is deprecated:"
115-
116-
- linters: [typecheck]
117-
text: "missing type in composite literal"
118-
119-
# TODO: Rewrite
120-
- path: pool\.go
121-
linters: [revive, govet, gocritic, misspell]
98+
formatters:
99+
enable:
100+
- gofmt
101+
- goimports
102+
settings:
103+
goimports:
104+
local-prefixes:
105+
- github.com/gotd/botapi

bot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func New(token string, opt Options) (*Bot, error) {
100100
}
101101

102102
// Run connects, authorizes as a bot, and blocks serving updates until ctx is
103-
// cancelled or a fatal error occurs. Register handlers before calling Run.
103+
// canceled or a fatal error occurs. Register handlers before calling Run.
104104
func (b *Bot) Run(ctx context.Context) error {
105105
return b.client.Run(ctx, func(ctx context.Context) error {
106106
status, err := b.client.Auth().Status(ctx)

markup.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ type ReplyMarkup interface {
1010
isReplyMarkup()
1111
}
1212

13-
func (*InlineKeyboardMarkup) isReplyMarkup() {}
14-
func (*ReplyKeyboardMarkup) isReplyMarkup() {}
15-
func (*ReplyKeyboardRemove) isReplyMarkup() {}
16-
func (*ForceReply) isReplyMarkup() {}
17-
1813
// WebAppInfo describes a Web App to be opened from a button.
1914
type WebAppInfo struct {
2015
URL string `json:"url"`
@@ -77,6 +72,11 @@ type ForceReply struct {
7772
Selective bool `json:"selective,omitempty"`
7873
}
7974

75+
func (*InlineKeyboardMarkup) isReplyMarkup() {}
76+
func (*ReplyKeyboardMarkup) isReplyMarkup() {}
77+
func (*ReplyKeyboardRemove) isReplyMarkup() {}
78+
func (*ForceReply) isReplyMarkup() {}
79+
8080
// --- Constructors / builders (the type-safe telegoutil equivalent) ---
8181

8282
// InlineKeyboard builds an inline keyboard from rows of buttons.

0 commit comments

Comments
 (0)