A custom linter for golangci-lint that ensures all time.Now() calls are followed by .UTC().
This linter helps prevent timezone-related bugs by ensuring that all time.Now() calls are immediately followed by .UTC(). This is particularly useful in applications where consistent timezone handling is critical.
This linter uses the golangci-lint Module Plugin System.
- Create a
.custom-gcl.ymlfile in your project root:
version: v2.6.2 # Use your desired golangci-lint version
plugins:
- module: 'github.com/road-labs/go-analyzer-utctime'
version: latest # or specify a version tag- Build a custom golangci-lint binary with the plugin:
$ golangci-lint customThis will create a ./custom-gcl binary that includes the plugin.
-
Configure the plugin in your
.golangci.yml(see Usage section below). -
Run your custom golangci-lint binary:
$ ./custom-gcl runAdd the linter to your .golangci.yml configuration:
version: "2"
linters:
enable:
- utctime
settings:
custom:
utctime:
type: module
description: Checks that time.Now() is followed by .UTC()// Bad:
t := time.Now() // Will trigger a linter error
// Good:
t := time.Now().UTC()MIT License
Contributions are welcome! Please feel free to submit a Pull Request.