Skip to content

road-labs/go-analyzer-utctime

 
 

Repository files navigation

go-analyzer-utctime

A custom linter for golangci-lint that ensures all time.Now() calls are followed by .UTC().

Description

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.

Installation

This linter uses the golangci-lint Module Plugin System.

  1. Create a .custom-gcl.yml file 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
  1. Build a custom golangci-lint binary with the plugin:
$ golangci-lint custom

This will create a ./custom-gcl binary that includes the plugin.

  1. Configure the plugin in your .golangci.yml (see Usage section below).

  2. Run your custom golangci-lint binary:

$ ./custom-gcl run

Usage

Add 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()

Examples

// Bad:
t := time.Now() // Will trigger a linter error

// Good:
t := time.Now().UTC()

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

Custom linter for golangci-lint to check time.Now().UTC() is being used

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 81.7%
  • Makefile 18.3%