Git Product home page Git Product logo

goimports's Introduction

This tool updates your Go import lines, adding missing ones and
removing unreferenced ones.

     $ go get github.com/bradfitz/goimports

It's a fork of gofmt, and will also format your code, so it can be
used as a replacement for your gofmt-on-save hook in your editor of
choice.

For emacs, make sure you have the latest (Go 1.2) go-mode.el:
   https://go.googlecode.com/hg/misc/emacs/go-mode.el

Then in your .emacs file:
   (setq gofmt-command "goimports")
   (add-to-list 'load-path "/home/you/goroot/misc/emacs/")
   (require 'go-mode-load)
   (add-hook 'before-save-hook 'gofmt-before-save)

For vim, set "gofmt_command" to "goimports":

    https://code.google.com/p/go/source/detail?r=39c724dd7f252
    https://code.google.com/p/go/source/browse#hg%2Fmisc%2Fvim
    etc

For Sublime Text 3 get your plugin at:
    https://github.com/ticcky/sublime_goimports.git

For other editors, you probably know what to do.

Happy hacking!

Caveats:

For removal, it assumes the import path base matches the package name,
which is best practice anyway, like:

    import "github.com/you/foo" // assumes this is package "foo"

If they don't match, explicitly name the package name in your import
line:

    import foo "github.com/you/not-quite-foo"

These caveats might be fixed.

goimports's People

Contributors

bradfitz avatar crawshaw avatar nikai3d avatar shawnps avatar ticcky avatar

Watchers

 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.