sachaos / pkgalias

A linter for Go to fix alias of package.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pkgalias

A linter for Go to fix alias of package.

Install

$ go install github.com/sachaos/pkgalias

Quickstart

1. Prepare config .pkgalias.yaml

settings:
- alias: validatorv10
  fullpath: github.com/go-playground/validator/v10

2. Example source code

package main

import "github.com/go-playground/validator/v10"

type User struct {
	Name string `validate:"required"`
}

func main() {
	user := &User{
		Name: "sachaos",
	}

	validate := validator.New()
	if err := validate.Struct(user); err != nil {
		panic(err)
	}
}

3. Run pkgalias

$ pkgalias ./
./main.go:3:8: invalid alias: package name should be "validatorv10", insert this.
./main.go:14:14: invalid alias: use "validatorv10" instead of "validator"

4. Fix automatically with -fix option

$ pkgalias -fix ./
./main.go:3:8: invalid alias: package name should be "validatorv10", insert this.
./main.go:14:14: invalid alias: use "validatorv10" instead of "validator"
package main

import validatorv10 "github.com/go-playground/validator/v10"

type User struct {
	Name string `validate:"required"`
}

func main() {
	user := &User{
		Name: "sachaos",
	}

	validate := validatorv10.New()
	if err := validate.Struct(user); err != nil {
		panic(err)
	}
}

About

A linter for Go to fix alias of package.

License:MIT License


Languages

Language:Go 100.0%