gci

command module
v0.2.9-0...-1e8cfed Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

README

GCI

GCI, a tool that control golang package import order and make it always deterministic.

It handles empty lines more smartly than goimport does.

Download

$ go get github.com/mathieupost/gci

Usage

$ gci -h
usage: gci [flags] [path ...]
  -d	display diffs instead of rewriting files
  -local string
    	put imports beginning with this string after 3rd-party packages, only support one string
  -w	write result to (source) file instead of stdout

Examples

Run gci -w -local github.com/mathieupost/gci main.go and you will handle following cases.

simple case
package main
import (
  "golang.org/x/tools"

  "fmt"

  "github.com/mathieupost/gci"
)

to

package main
import (
  "fmt"

  "golang.org/x/tools"

  "github.com/mathieupost/gci"
)
with alias
package main
import (
  "fmt"
  go "github.com/golang"
  "github.com/mathieupost"
)

to

package main
import (
  "fmt"

  go "github.com/golang"

  "github.com/mathieupost/gci"
)
with comment and alias
package main
import (
  "fmt"
  _ "github.com/golang" // golang
  "github.com/mathieupost"
)

to

package main
import (
  "fmt"

  // golang
  _ "github.com/golang"

  "github.com/mathieupost/gci"
)
with above comment and alias
package main
import (
  "fmt"
  // golang
  _ "github.com/golang"
  "github.com/mathieupost"
)

to

package main
import (
  "fmt"

  // golang
  _ "github.com/golang"

  "github.com/mathieupost/gci"
)

TODO

  • Support multi-3rd-party packages
  • Support multiple lines of comment in import block
  • Add testcases

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
gci

Jump to

Keyboard shortcuts

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