Giter VIP home page Giter VIP logo

fancyfmt's Introduction

fancyfmt

A formatter for Go code with bells and whistles

Installation

  • Use

    go get github.com/sirkon/fancyfmt

    to get a library as a dependency of your custom formatter.

  • Type

    GO111MODULE=on go get github.com/sirkon/cmd/fancyfmt

    to install a ready to use formatter

Description

fancyfmt is a

  • library to make gofmt compliant formatters
  • a ready to use formatter

Brief functionality

  • Imports grouping and sorting. Import paths are:
    • Joined in one import declaration (except "C", which is always alone)
    • Splitted in groups (can be tweaked with custom imports grouper)
    • Sorted lexicographically within each group
  • Provides default formatting for
    • Multiline functions declarations
    • Multiline calls
    • Multiline composite literals, slices and arrays get a special care at that
    • Multiline chaining

Screencast

usage screencast

Remarks

  • fancyfmt stores a cache of packages from standard library in a os.TempDir() directory. This was done to speedup things as package.Load(cfg, "std") is slow, about 0.2s on my machine, cached access is about ten times faster. You may notice a slugishness in case of the first formatting in the screencast, that is it. The further formats are much faster.
  • fancyfmt mutates []byte{โ€ฆ} literals if they only have numbers replacing them with hex numbers.
  • You may fix composite literals formatting (except the new line before the first item and after the last one) by adding a comment after an element.

fancyfmt's People

Contributors

sirkon avatar

Watchers

 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.