Git Product home page Git Product logo

importsort's Introduction

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"
    }
  ]

importsort's People

Contributors

kanziw avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.