git-fmt: Custom git command for formatting code.

[ bsd3, development, program ] [ Propose Tags ]

git-fmt adds a custom command to Git that automatically formats code by using external pretty-printers. The idea was taken from gofmt, just with a bit of expansion to more languages.


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.2.0.0, 0.2.0.1, 0.2.0.2, 0.2.1.0, 0.2.1.1, 0.2.1.2, 0.2.2.0, 0.2.2.1, 0.3.0.0, 0.3.0.1, 0.3.0.2, 0.3.0.3, 0.3.0.4, 0.3.0.5, 0.3.1.0, 0.3.1.1, 0.3.1.2, 0.4.0.0, 0.4.1.0
Change log CHANGELOG.md
Dependencies aeson (>=0.8 && <0.9), base (>=4.8 && <4.9), directory (>=1.2 && <1.3), exceptions (>=0.8 && <0.9), extra (>=1.4 && <1.5), fast-logger (>=2.4 && <2.5), filepath (>=1.4 && <1.5), git-fmt, monad-logger (>=0.3 && <0.4), monad-parallel (>=0.7 && <0.8), mtl (>=2.2 && <2.3), optparse-applicative (>=0.11 && <0.12), process (>=1.2 && <1.3), temporary (>=1.2 && <1.3), text (>=1.2 && <1.3), time (>=1.5 && <1.6), transformers (>=0.4 && <0.5), unordered-containers (>=0.2 && <0.3), yaml (>=0.8 && <0.9) [details]
License BSD-3-Clause
Author Henry J. Wylde
Maintainer public@hjwylde.com
Category Development
Home page https://github.com/hjwylde/git-fmt
Source repo head: git clone git@github.com:hjwylde/git-fmt
Uploaded by hjwylde at 2015-12-09T10:30:54Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Executables git-fmt
Downloads 14825 total (48 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-12-09 [all 1 reports]

Readme for git-fmt-0.2.0.2

[back to package description]

git-fmt

Project Status: Wip - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. Build Status Release

(Side note: the formatting component of this project will eventually be split out and named omnifmt.)

git-fmt adds a custom command to Git that automatically formats code by using external pretty-printers. The idea was taken from gofmt, just with a bit of expansion to more languages.

Formatted code is:

  • Easier to write: never worry about minor formatting concerns while hacking away.
  • Easier to read: when all code looks the same you need not mentally convert others' formatting style into something you can understand.
  • Easier to maintain: mechanical changes to the source don't cause unrelated changes to the file's formatting; diffs show only the real changes.
  • Uncontroversial: never have a debate about spacing or brace position ever again.

(Bullet points taken from https://blog.golang.org/go-fmt-your-code.)

Installing

Installing git-fmt is easiest done using either stack (recommended) or Cabal. Alternatively you may download a pre-compiled binary of the latest release.

Using stack:

stack install git-fmt
export PATH=$PATH:~/.local/bin

Using Cabal:

cabal-install git-fmt
export PATH=$PATH:~/.cabal/bin

Usage

git-fmt itself just provides a way to select files in the git repository and pipe them through a pretty-printer. It also provides a dry-run mode that will show you which files need prettifying.

Configuration

Configuration is done through an .omnifmt.yaml file in the repository's top-level directory.

To show how, here's an example .omnifmt.yaml:

haskell:
    extensions: ["hs", "lhs"]
    command:    "stylish-haskell {{input}} > {{output}}"

javascript:
    extensions: ["js"]
    command:    "js-beautify {{input}} > {{output}}"

json:
    extensions: ["json"]
    command:    "json_pp < {{input}} > {{output}}"

That's all it takes! Each command must declare how to read the input file and how to write to the temporary file. The temporary file is used to compare whether the original input was pretty or ugly before writing to the original.

Extensions is pretty self explanatory, but if you use the same extension more than once then precedence goes to the first defined pretty-printer.