Skip to content

Similar to goimport, but makes the grouping clearer.

Notifications You must be signed in to change notification settings

atotto/gogroupimports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gogroupimports

Similar to goimport, but makes the grouping clearer.

The gogroupimports tool organizes the Go imports and rewrites them according to the following:

  • First group: The standard library packages
  • Next group: 3rd party library packages
  • Last group: local packages

example:

import (
	// The standard library packages
	"context"
	"fmt"
	"testing"

	// 3rd party library packages
	"google.golang.org/grpc"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"google.golang.org/protobuf/proto"

	// local packages
	"github.com/atotto/awesome"
)

Installation

go install github.com/atotto/gogroupimports@latest
go install golang.org/x/tools/cmd/goimports@latest

Example of use

before:

import (
	"testing"

	"context"
	"fmt"
	
	"github.com/atotto/awesome"
	"google.golang.org/grpc"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	
	"google.golang.org/protobuf/proto"
)
gogroupimports -local github.com/atotto/awesome -w foo.go

after:

import (
	"context"
	"fmt"
	"testing"

	"google.golang.org/grpc"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"google.golang.org/protobuf/proto"

	"github.com/atotto/awesome"
)

vs goimports

The goimports tool does not delete empty line. Like this:

goimports -local github.com/atotto/awesome -w foo.go
import (
	"context"
	"fmt"
	"testing"

	"google.golang.org/grpc"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"

	"github.com/atotto/awesome"
	
	"google.golang.org/protobuf/proto"
)

About

Similar to goimport, but makes the grouping clearer.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages