• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

src/H09-Sep-2001-1,9931,600

tests/H09-Sep-2001-2,4571,634

CHANGELOGH A D09-Sep-20011.9 KiB8853

LICENSEH A D09-Sep-20011.5 KiB3124

README.mdH A D09-Sep-20013.1 KiB10567

Setup.hsH A D09-Sep-200146 32

apply-refact.cabalH A D09-Sep-20015.1 KiB160153

README.md

1`apply-refact` applies refactorings specified by the
2[`refact`](https://hackage.haskell.org/package/refact) package. It is currently
3integrated into [HLint](https://github.com/ndmitchell/hlint) to enable the automatic application of suggestions.
4
5# Install
6
7```shell
8cabal install apply-refact
9```
10
11Alternatively, clone the repo and run `cabal install`.
12
13You can also install from Nix:
14
15```shell
16nix-env -iA nixpkgs.haskellPackages.apply-refact
17```
18
19Executable name is `refactor`.
20
21#### Hlint Integration example
22
23```shell
24hlint src/Main.hs --refactor --refactor-options="--inplace"
25```
26
27# Example Usage
28
29<img src="http://i.imgur.com/7YXoVft.gif">
30
31```
32# test.hs
33
34foo = (x)
35
36# hlint.refact -- produced by hlint --serialise
37[("test.hs:1:7: Warning: Redundant bracket\nFound:\n  (x)\nWhy not:\n
38x\n",[Replace {rtype = Expr, pos = SrcSpan {startLine = 1, startCol = 7, endLine
39= 1, endCol = 10}, subts = [("x",SrcSpan {startLine = 1, startCol = 8, endLine =
401, endCol = 9})], orig = "x"}])]
41
42> refactor test.hs --refact-file hlint.refact
43foo = x
44```
45
46One of either the input file or `--refact-file` must be specified on the command
47line. If an input file is specified but not `--refact-file` then `refactor` will
48accept refactorings from stdin and vice versa.
49
50The `-i` option can be specified to perform the refactoring inplace overwriting
51the input file. This option is ignored when input is read from stdin.
52
53The `-s` option can be specified to perform a stepwise evaluation of the refact
54file. The user is prompted whether to perform each hint before it is performed.
55
56The `--pos` option is intended to be used by tooling in order to specify which
57specific hint should be performed.
58
59Multiple `-X` options may be provided to specify additional default language pragmas which might affect parsing, such as `-XLambdaCase` or `-XRankNTypes`.
60
61## Refact Files
62
63Refact files should be the result of `show` on a value of type `[(String,
64[Refactoring SrcSpan])]`. The string is a description of the refactoring, one
65description can have many associated refactoring steps.
66
67
68## Library Structure
69
70The executable is provide so that libraries can use `apply-refact` without depending on the package.
71The implementation relies on `ghc-exactprint` which depends itself on GHC. A
72transitive dependancy that most developers wish to avoid!
73
74
75# Reporting Bugs
76
77If the program produces a syntactically incorrect result then this is a bug.
78Please open an issue on the issue tracker with precise instructions about how to
79reproduce it.
80
811. The input file
822. The refact file
833. The command used to invoke `refactor`
84
85There are some known problems with CPP processing. If your library contains CPP
86directives other than `#ifdef` it is quite likely that the result will be
87unexpected.
88
89# Debugging
90
91There are also two hidden flags which can be useful for debugging.
92
93#### `--debug`
94
95Outputs the GHC AST.
96
97#### `--roundtrip`
98
99Performs no refactoring operations on the file but is useful to test whether
100unexpected formatting is due to `ghc-exactprint` or the refactoring.
101
102# Contributing
103
104Contributions are welcome. You can run the tests via `cabal test`.
105