Skip to content

Conversation

@coxley
Copy link
Contributor

@coxley coxley commented Oct 23, 2025

Summary

This addresses a gap where multiplication assignments were not checked:

package main

import "time"

func main() {
	x := time.Second
	x = x * time.Hour  // durationcheck: Multiplication of durations
	x *= time.Hour     // nothing
}

I recommend this linter occasionally, but zimpenfish pointed out it missed this case in some of their code: https://lobste.rs/c/7pbivg

PS: I updated go.mod to 1.16. We have a dependency on golang.org/x/tools@v0.6.0, which uses io.ReadAll. The dependency itself declares go 1.18 // tagx:compat 1.16, but figured I'd avoid upping the requirement more than necessary.

Test Plan

> docker run -it -v=$(pwd):/app --workdir=/app --rm golang:1.16 sh -c 'go mod tidy && go test'
go: downloading golang.org/x/tools v0.6.0
go: downloading golang.org/x/sys v0.5.0
go: downloading golang.org/x/mod v0.8.0
go: downloading golang.org/x/sync v0.1.0
PASS
ok      github.com/charithe/durationcheck       0.774s

Using Docker because the tests are broken with Go binaries >= 1.22, but that's not our fault: golang/go#75918 (comment)

@charithe
Copy link
Owner

Thank you for the fix and the really helpful PR description. I haven't touched this project for a while and didn't notice that issue with Go 1.22 and above. I wonder how the golangci-lint folks manage to build it.

@charithe charithe merged commit 2d901f8 into charithe:master Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants