Skip to content

Commit 18744ef

Browse files
JoTurkrealtlos
authored andcommitted
chore: change lint settings and apply modernize
1 parent 91ef2f5 commit 18744ef

File tree

10 files changed

+41
-36
lines changed

10 files changed

+41
-36
lines changed

.golangci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ linters:
3838
- maintidx # maintidx measures the maintainability index of each function.
3939
- makezero # Finds slice declarations with non-zero initial length
4040
- misspell # Finds commonly misspelled English words in comments
41-
- mnd # An analyzer to detect magic numbers
41+
- modernize # Replace and suggests simplifications to code
4242
- nakedret # Finds naked returns in functions greater than a specified function length
4343
- nestif # Reports deeply nested if statements
4444
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
@@ -49,7 +49,6 @@ linters:
4949
- revive # golint replacement, finds style mistakes
5050
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
5151
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
52-
- tagliatelle # Checks the struct tags.
5352
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
5453
- unconvert # Remove unnecessary type conversions
5554
- unparam # Reports unused function parameters
@@ -64,11 +63,13 @@ linters:
6463
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
6564
- interfacebloat # A linter that checks length of interface.
6665
- ireturn # Accept Interfaces, Return Concrete Types
66+
- mnd # An analyzer to detect magic numbers
6767
- nolintlint # Reports ill-formed or insufficient nolint directives
6868
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
6969
- prealloc # Finds slice declarations that could potentially be preallocated
7070
- promlinter # Check Prometheus metrics naming via promlint
7171
- rowserrcheck # checks whether Err of rows is checked successfully
72+
- tagliatelle # Checks the struct tags.
7273
- testpackage # linter that makes you use a separate _test package
7374
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
7475
- wrapcheck # Checks that errors returned from external packages are wrapped
@@ -141,4 +142,7 @@ formatters:
141142
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
142143
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
143144
exclusions:
144-
generated: lax
145+
generated: lax
146+
issues:
147+
max-issues-per-linter: 0
148+
max-same-issues: 0

api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (a *Server) registerRoute(route Route) {
105105
func GenericResponse(
106106
writer http.ResponseWriter,
107107
code int,
108-
response interface{},
108+
response any,
109109
start time.Time,
110110
) {
111111
writer.Header().Set("Content-Type", "application/json")

api/middleware/authenticate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type potatClaims struct {
3434
type unauthFunc func(
3535
w http.ResponseWriter,
3636
status int,
37-
response interface{},
37+
response any,
3838
start time.Time,
3939
)
4040

@@ -130,7 +130,7 @@ func (a *Authenticator) verifyDynamicAuth(ctx context.Context, token string) (bo
130130
return true, user
131131
}
132132

133-
func (a *Authenticator) jwtKeyFunc(token *jwt.Token) (interface{}, error) {
133+
func (a *Authenticator) jwtKeyFunc(token *jwt.Token) (any, error) {
134134
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
135135
return nil, fmt.Errorf("%w: unexpected signing method: %v", errUnexpectedSign, token.Header["alg"])
136136
}

api/middleware/ratelimit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func getIPToken(
9191
return false, 0, 0, err
9292
}
9393

94-
results, ok := result.([]interface{})
94+
results, ok := result.([]any)
9595
if !ok {
9696
return false, 0, 0, errBadRedisResponse
9797
}

common/db/loops.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,13 @@ func updateOwnedBadgeView(ctx context.Context, clickhouse *ClickhouseClient) {
274274

275275
// Insert owned badges from active table first
276276
// prepare := `
277-
// INSERT INTO potatbotat.twitch_owned_badges
278-
// SELECT
279-
// badge,
280-
// user_id,
281-
// version
282-
// FROM potatbotat.twitch_badges
283-
// WHERE badge NOT IN ('', 'NOBADGE')
277+
// INSERT INTO potatbotat.twitch_owned_badges
278+
// SELECT
279+
// badge,
280+
// user_id,
281+
// version
282+
// FROM potatbotat.twitch_badges
283+
// WHERE badge NOT IN ('', 'NOBADGE')
284284
// `
285285

286286
// err := clickhouse.Exec(ctx, prepare)

common/db/postgres.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ func (db *PostgresClient) getChannelByType( //nolint:cyclop
330330
FROM channels c
331331
`
332332

333-
switch {
334-
case chanType == "ID":
333+
switch chanType {
334+
case "ID":
335335
query += `WHERE c.channel_id = $1 `
336-
case chanType == "NAME":
336+
case "NAME":
337337
query += `WHERE c.username = $1 `
338338
default:
339339
return nil, errInvalidType
@@ -394,9 +394,10 @@ func (db *PostgresClient) getChannelByType( //nolint:cyclop
394394
}
395395

396396
for _, block := range blocks {
397-
if block.BlockType == common.UserBlock {
397+
switch block.BlockType {
398+
case common.UserBlock:
398399
*channel.Blocks.Users = append(*channel.Blocks.Users, block)
399-
} else if block.BlockType == common.CommandBlock {
400+
case common.CommandBlock:
400401
*channel.Blocks.Commands = append(*channel.Blocks.Commands, block)
401402
}
402403
}

common/normalemote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type TwitchEmote struct {
107107

108108
// NewNormalEmote returns a normalized emote object based on the provided emote data and platform.
109109
func NewNormalEmote( //nolint:cyclop
110-
emoteData interface{},
110+
emoteData any,
111111
setID string,
112112
provider Platforms,
113113
emoteType EmoteType,

common/types.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ type TwitchRoles struct {
9898

9999
// Channel represents a channel on a platform, including its blocks, settings, commands, and other metadata.
100100
type Channel struct {
101-
Blocks FilteredBlocks `json:"blocks,omitempty"`
102-
JoinedAt *time.Time `json:"joined_at,omitempty"`
103-
Meta map[string]interface{} `json:"meta"`
104-
Commands *[]ChannelCommand `json:"commands,omitempty"`
105-
ChannelID string `json:"channel_id"`
106-
Username string `json:"username"`
107-
Platform Platforms `json:"platform"`
108-
State string `json:"state"`
109-
AddedBy []AddedByData `json:"added_by,omitempty"`
110-
Editors []string `json:"editors"`
111-
Ambassadors []string `json:"ambassadors"`
112-
Settings ChannelSettings `json:"settings"`
101+
Blocks FilteredBlocks `json:"blocks,omitempty"`
102+
JoinedAt *time.Time `json:"joined_at,omitempty"`
103+
Meta map[string]any `json:"meta"`
104+
Commands *[]ChannelCommand `json:"commands,omitempty"`
105+
ChannelID string `json:"channel_id"`
106+
Username string `json:"username"`
107+
Platform Platforms `json:"platform"`
108+
State string `json:"state"`
109+
AddedBy []AddedByData `json:"added_by,omitempty"`
110+
Editors []string `json:"editors"`
111+
Ambassadors []string `json:"ambassadors"`
112+
Settings ChannelSettings `json:"settings"`
113113
}
114114

115115
// FilteredBlocks represents the blocks of users and commands in a channel.
@@ -379,7 +379,7 @@ const (
379379
)
380380

381381
// Flags represents a map of flags, where each flag is identified by a string key and can hold any type of value.
382-
type Flags map[string]interface{}
382+
type Flags map[string]any
383383

384384
// CommandConditions represents the conditions under which a command can be executed.
385385
type CommandConditions struct {

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func runWithTimeout(
151151
done := make(chan error, 1)
152152

153153
var lastError error
154-
for i := 0; i < 3; i++ {
154+
for range 3 {
155155
attemptCtx, cancel := context.WithTimeout(ctx, 1*time.Second)
156156
defer cancel()
157157

redirects/redirects.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func (r *redirects) cleanRedirectProtocolSoLinksActuallyWork(url string) string
8888
if strings.HasPrefix(url, "https://") {
8989
return url
9090
}
91-
if strings.HasPrefix(url, "http://") {
92-
return "https://" + strings.TrimPrefix(url, "http://")
91+
if after, ok := strings.CutPrefix(url, "http://"); ok {
92+
return "https://" + after
9393
}
9494
if strings.HasPrefix(url, "//") {
9595
return "https:" + url

0 commit comments

Comments
 (0)