importsort

command module
v0.0.0-...-52de941 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

README

importsort

Inspired by https://github.com/aristanetworks/goarista/tree/master/cmd/importsort

What's this?

It sorts golang imports into 3 groups like -

  1. Standard packages
  2. Third-party packages
  3. your (e.g. cvshub.com/company) packages
import (
	"bytes"
	"strings"

	"github.com/pkg/errors"

	a "cvshub.com/company/p"
	"cvshub.com/company/q"
)

Install

go install github.com/kanziw/importsort@latest

Usage

Usage of importsort:
  -l	list files whose formatting differs from importsort
  -s prefix
    	package prefix to define an import section, ex: "cvshub.com/company". May be specified multiple times. If not specified the repository root is used.
  -w	write result to file instead of stdout
Example
importsort -s github.com/kanziw -w main.go
How to set in GoLand
  1. Download importsort.xml
  2. Preferences -> Tools -> File Watchers -> Import importsort.xml
How to set in VSCode
  1. Install File Watcher
  2. Edit setting.json
  "filewatcher.commands": [
    {
      "match": "\\.go$",
      "isAsync": true,
      "cmd": "importsort -s cvshub.com/company -w ${file}",
      "event": "onFileChange"
    }
  ]

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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