strictgoimports

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2023 License: MIT Imports: 10 Imported by: 0

README

strictgoimports

strictgoimports is made to resolve an issue goimports has. The issue is still discussed here.

Install

$ go install github.com/momotaro98/strictgoimports/cmd/strictgoimports@latest

Usage

Use as checker
$ strictgoimports -exclude "*_mock.go,*.pb.go" -exclude-dir "testmock" -local "github.com/momotaro98/mixlunch-service-api" $HOME/.ghq/github.com/momotaro98/mixlunch-service-api

You'll see instructions like below.

/Users/shintaro/.ghq/github.com/momotaro98/mixlunch-service-api/partyservice/domain_test.go:8:2: import not sorted correctly. should be replace to
import (
        "errors"
        "testing"
        "time"

        "github.com/golang/mock/gomock"

        "github.com/momotaro98/mixlunch-service-api/userservice"
        "github.com/momotaro98/mixlunch-service-api/utils"
)
/Users/shintaro/.ghq/github.com/momotaro98/mixlunch-service-api/userservice/provider.go:5:2: import not sorted correctly. should be replace to
import (
        "github.com/google/wire"

        "github.com/momotaro98/mixlunch-service-api/tagservice"
)
/Users/shintaro/.ghq/github.com/momotaro98/mixlunch-service-api/wire.go:8:2: import not sorted correctly. should be replace to
import (
        "github.com/google/wire"

        "github.com/momotaro98/mixlunch-service-api/logger"
        "github.com/momotaro98/mixlunch-service-api/partyservice"
        "github.com/momotaro98/mixlunch-service-api/tagservice"
        usService "github.com/momotaro98/mixlunch-service-api/userscheduleservice"
        "github.com/momotaro98/mixlunch-service-api/userservice"
)
Use as modifier

You can modify all of the target files by using -w option.

$ strictgoimports -w -local "github.com/username/repo" .

This results in fixing import paths.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(filePath, localPaths string) (fileSet *token.FileSet, pos []token.Pos, correctImport string, fixed []byte)

Types

type Err

type Err struct {
	Pos     token.Pos
	Message string
	FileSet *token.FileSet
}

func (*Err) Error

func (e *Err) Error() string

type ImportLines

type ImportLines []*imptLine

func (ImportLines) String

func (ils ImportLines) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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