on 0.0.3.0 help sign in
ormolu/README.md
137 lines 4.6 kB history raw
1# Ormolu
3[![License BSD3](https://img.shields.io/badge/license-BSD3-brightgreen.svg)](http://opensource.org/licenses/BSD-3-Clause)
4[![Hackage](https://img.shields.io/hackage/v/ormolu.svg?style=flat)](https://hackage.haskell.org/package/ormolu)
5[![Stackage Nightly](http://stackage.org/package/ormolu/badge/nightly)](http://stackage.org/nightly/package/ormolu)
6[![Stackage LTS](http://stackage.org/package/ormolu/badge/lts)](http://stackage.org/lts/package/ormolu)
7[![CircleCI](https://circleci.com/gh/tweag/ormolu/tree/master.svg?style=svg&circle-token=cfd37a39265561eb44e608f97cf953cb2a394c03)](https://circleci.com/gh/tweag/ormolu/tree/master)
9Ormolu is a formatter for Haskell source code. The project was created with
10the following goals in mind:
12* Using GHC's own parser to avoid parsing problems caused by
13 [`haskell-src-exts`][haskell-src-exts].
14* Let some whitespace be programmable. The layout of the input influences
15 the layout choices in the output. This means that the choices between
16 single-line/multi-line layouts in each particular situation are made by
17 the user, not by an algorithm. This makes the implementation simpler and
18 leaves some control to the user while still guaranteeing that the
19 formatted code is stylistically consistent.
20* Writing code in such a way so it's easy to modify and maintain.
21* Implementing one “true” formatting style which admits no configuration.
22* That formatting style aims to result in minimal diffs while still
23 remaining very close to “conventional” Haskell formatting people use.
24* Choose a style compatible with modern dialects of Haskell. As new Haskell
25 extensions enter broad use, we may change the style to accomodate them.
26* Idempotence: formatting already formatted code doesn't change it.
27* Be well-tested and robust to the point that it can be used in large
28 projects without exposing unfortunate, disappointing bugs here and there.
30## Building
32The easiest way to build the project is with Nix:
34```console
35$ nix-build -A ormolu
36```
38Or with `cabal-install` from the Nix shell:
40```console
41$ nix-shell --run "cabal new-build"
42```
44Alternatively, `stack` could be used with a `stack.yaml` file as follows.
46```console
47$ cat stack.yaml
48resolver: lts-14.3
49packages:
50- '.'
52$ stack build
53```
55To use Ormolu directly from GitHub with Nix, this snippet may come in handy:
57```nix
58# This overlay adds Ormolu straight from GitHub.
59self: super:
61let source = super.fetchFromGitHub {
62 owner = "tweag";
63 repo = "ormolu";
64 rev = "de279d80122b287374d4ed87c7b630db1f157642"; # update as necessary
65 sha256 = "0qrxfk62ww6b60ha9sqcgl4nb2n5fhf66a65wszjngwkybwlzmrv"; # as well
66 };
67 ormolu = import source { pkgs = self; };
68in {
69 haskell = super.haskell // {
70 packages = super.haskell.packages // {
71 "${ormolu.ormoluCompiler}" = super.haskell.packages.${ormolu.ormoluCompiler}.override {
72 overrides = ormolu.ormoluOverlay;
73 };
74 };
75 };
77```
79## Usage
81The following will print the formatted output to the standard output.
83```console
84$ ormolu Module.hs
85```
87Add `--mode inplace` to replace the contents of the input file with the
88formatted output.
90```console
91$ ormolu --mode inplace Module.hs
92```
94## Current limitations
96* Does not handle CPP (wontfix, see [the design document][design]).
97* Input modules should be parsable by Haddock, which is a bit stricter
98 criterion than just being valid Haskell modules.
99* Various minor idempotence issues, most of them are related to comments.
101## Editor integration
103We know of the following editor integrations:
105* [Emacs][emacs-package]
106* [VS Code][vs-code-plugin]
108## Running on Hackage
110It's possible to try Ormolu on arbitrary packages from Hackage. For that
111execute (from the root of the cloned repo):
113```console
114$ nix-build -A hackage.<package>
115```
117Then inspect `result/log.txt` for possible problems. The derivation will
118also contain formatted `.hs` files for inspection and original inputs with
119`.hs-original` extension (those are with CPP dropped, exactly what is fed
120into Ormolu).
122## Contributing
124See [CONTRIBUTING.md][contributing].
126## License
128See [LICENSE.md][license].
130Copyright © 2018–present Tweag I/O
132[design]: https://github.com/tweag/ormolu/blob/master/DESIGN.md#cpp
133[contributing]: https://github.com/tweag/ormolu/blob/master/CONTRIBUTING.md
134[license]: https://github.com/tweag/ormolu/blob/master/LICENSE.md
135[haskell-src-exts]: https://hackage.haskell.org/package/haskell-src-exts
136[emacs-package]: https://github.com/vyorkin/ormolu.el
137[vs-code-plugin]: https://marketplace.visualstudio.com/items?itemName=sjurmillidahl.ormolu-vscode