Skip to content

Prefer any over interface{} Has Fix

Description

Go 1.18 introduced any as an alias for interface{}. The shorter name makes unconstrained values and type parameters easier to recognize.

Use this rule only when the project targets Go 1.18 or newer, and review code that declares its own identifier named any.

YAML

yaml
id: use-any
language: Go
rule:
  pattern: interface{}
fix: any

Example

go
func Decode(v interface{}) error { return nil }

Diff

go
func Decode(v interface{}) error { return nil } 
func Decode(v any) error { return nil } 

Credits

Inspired by JetBrains' Go Modern Guidelines.

Made with ❤️ with Rust