Giter VIP home page Giter VIP logo

go-groups's Introduction

go-groups

Go Report Card Build Status GoDoc NetflixOSS Lifecycle GitHub

Project Overview

Command go-groups is a CLI tool to deterministically rewrite go import blocks to sort and re-group the imports.

go-groups is similar to goimports, but in addition to sorting imports lexigraphically, it also separates import blocks at a per-project level. Like goimports, go-groups also runs gofmt and fixes any style/formatting issues.

Getting Started

The go-groups command can be installed by running:

$ go install oss.indeed.com/go/go-groups@latest

Usage

$ go-groups -h
  usage: go-groups [flags] [path ...]
    -d    display diffs instead of rewriting files
    -f    disables the automatic gofmt style fixes
    -g    include generated code in analysis
    -l    list files whose formatting differs
    -v    display the version of go-groups
    -w    write result to (source) file instead of stdout

Formatting Behavior

With this example source file input

import (
  "strings"
  "github.com/pkg/errors"
  "fmt"
  "github.com/gorilla/mux"
  "github.com/gorilla/csrf"
)

Running go-groups will produce

import (
  "fmt"
  "strings"
  
  "github.com/gorilla/csrf"
  "github.com/gorilla/mux"
  
  "github.com/pkg/errors"
)

Typical Workflow

Run go-groups -w ./.. to rewrite and sort import groupings for go source files in a project.

Asking Questions

For technical questions about go-groups, just file an issue in the GitHub tracker.

For questions about Open Source in Indeed Engineering, send us an email at [email protected]

Contributing

We welcome contributions! Feel free to help make go-groups better.

Process

  • Open an issue and describe the desired feature / bug fix before making changes. It's useful to get a second pair of eyes before investing development effort.
  • Make the change. If adding a new feature, remember to provide tests that demonstrate the new feature works, including any error paths. If contributing a bug fix, add tests that demonstrate the erroneous behavior is fixed.
  • Open a pull request. Automated CI tests will run. If the tests fail, please make changes to fix the behavior, and repeat until the tests pass.
  • Once everything looks good, one of the indeedeng members will review the PR and provide feedback.

Maintainers

The oss.indeed.com/go/go-groups module is maintained by Indeed Engineering.

While we are always busy helping people get jobs, we will try to respond to GitHub issues, pull requests, and questions within a couple of business days.

Code of Conduct

oss.indeed.com/go/go-groups is governed by the Contributer Covenant v1.4.1

For more information please contact [email protected].

License

The oss.indeed.com/go/go-groups module is open source under the BSD-3-Clause license.

go-groups's People

Contributors

cnmcavoy avatar duaneobrien avatar mjpitz avatar shoenig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-groups's Issues

go-groups does not respect "dot" imports

go version: 1.14.5
go-groups version: 0.0.1

package main

import (
	"fmt"
	"testing"

	. "github.com/onsi/gomega"
	. "github.com/onsi/ginkgo"
)

func main() {
	fmt.Println("Hello world")

	RegisterFailHandler(Fail)
	RunSpecsWithDefaultAndCustomReporters(&testing.T{},
		"Controller Suite",
		[]Reporter{})
}

goimports properly re-ordered the imports, but go-groups removes the import lines.

Support ignoring generated source files

Although most generated source files will produce gofmt-compliant code they will often produce Go source that does not adhere to the go-groups import style. It would be good if go-groups supported an option to detect and ignore generated source files based on the documented comment convention:

^// Code generated .* DO NOT EDIT.$

Support cleaning up unused imports

Right now, I find myself needing both this tool and goimports. As far as I can tell, the only thing goimports does that go-groups does not is clean up unused imports. It would be nice if go-groups supported this as it would drop the need for goimports almost entirely.

Add install.sh script or equivalent

Right now, I need to manually download the binary and move it into position. Can we provide a simple shell script that downloads the binary for the appropriate os/architecture that and places it in the users path?

use of go fmt example in the README is incorrect

E.g.

$ go-groups -w ./..
$ go fmt -w ./..
flag provided but not defined: -w
usage: go fmt [-n] [-x] [packages]
Run 'go help fmt' for details.
$ gofmt -w ./..

We should reference gofmt instead of go fmt

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.