gencon

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2022 License: MIT Imports: 6 Imported by: 0

README

gencon Go Reference

gencon is an analyzer which reports unnecessary type constraints any.

gencon consists of two command, gencon and fixgencon.

  • gencon
    • finds type constraints any and gives hints of type constraints.
  • fixgencon
    • finds type constraints any and fix any to appropriate type constraints.

requirement

gencon and fixgencon requires Go 1.18+.

gencon command


package a

func f[T any](t T) {} // want "should not use 'any'. hint: string|~int"

func invoke() { // OK
	f("gopher")
	f(1)
	type MyInt int
	f(MyInt(18))
}

gencon reports the function only with any constraint, not other constraints such as comparable or constraints.Ordered.

If the function isn't called from anywhere, gencon reports without hint.

We can see example of gencon command report here.

install
$ go install github.com/arkuchy/gencon/cmd/gencon@latest
usage
$ go vet -vettool=`which gencon` pkgname

fixgencon

fixgencon is under development and supports only single type parameter.

--- before `fixgencon` ---

package a

func f[T any](t T) {} // want "should not use 'any'. hint: string|~int"

func g[T, U any, V int](t T, u U, v V) {} // want "should not use 'any'. hint: bool|int" "should not use 'any'. hint: string|~int"

func invoke() { // OK
	f("gopher")
	f(1)
	type MyInt int
	f(MyInt(18))

	g(3, "gopher", 100)
	g(true, MyInt(3), 100)
}

--- after `fixgencon` ---

package a

func f[T string | ~int](t T) {} // want "should not use 'any'. hint: string|~int"

func g[T, U any, V int](t T, u U, v V) {} // want "should not use 'any'. hint: bool|int" "should not use 'any'. hint: string|~int"

func invoke() { // OK
	f("gopher")
	f(1)
	type MyInt int
	f(MyInt(18))

	g(3, "gopher", 100)
	g(true, MyInt(3), 100)
}

fixgencon doesn't fix any when the function isn't called from anywhere, because fixgencon doesn't know what to change from any.

install
$ go install github.com/arkuchy/gencon/cmd/fixgencon@latest
usage
$ fixgencon ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "gencon",
	Doc:  doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Analyzer is ...

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL