apply-refact: Perform refactorings specified by the refact library.

[ bsd3, development, library, program ] [ Propose Tags ]

Perform refactorings specified by the refact library.


[Skip to Readme]

Downloads

Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.3.0.1, 0.4.0.0, 0.4.1.0, 0.5.0.0, 0.6.0.0, 0.7.0.0, 0.8.0.0, 0.8.1.0, 0.8.2.0, 0.8.2.1, 0.9.0.0, 0.9.1.0, 0.9.2.0, 0.9.3.0, 0.10.0.0, 0.11.0.0, 0.12.0.0, 0.13.0.0, 0.14.0.0
Change log CHANGELOG
Dependencies base (>=4.8 && <4.10), containers, directory, filemanip, filepath, ghc (>=8.0.1 && <8.1), ghc-exactprint (>=0.5.2), mtl, optparse-applicative (>=0.13), process, refact (>=0.2), syb, temporary, transformers, unix-compat [details]
License BSD-3-Clause
Author Matthew Pickering
Maintainer matthewtpickering@gmail.com
Category Development
Source repo head: git clone https://github.com/mpickering/apply-refact.git
Uploaded by mpickering at 2016-12-12T17:51:08Z
Distributions Arch:0.11.0.0, LTSHaskell:0.13.0.0, NixOS:0.13.0.0, Stackage:0.14.0.0
Reverse Dependencies 2 direct, 1 indirect [details]
Executables refactor
Downloads 25149 total (259 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for apply-refact-0.3.0.1

[back to package description]

apply-refact applies refactorings specified by the refact package. It is currently integrated into hlint to enable the automatic application of suggestions.

install

stack --resolver=nightly install apply-refact

executable name is refactor

Hlint Integration example

hlint src/Main.hs --refactor --refactor-options="--inplace"

Example Usage

# test.hs

foo = (x)

# hlint.refact -- produced by hlint --serialise
[("test.hs:1:7: Warning: Redundant bracket\nFound:\n  (x)\nWhy not:\n
x\n",[Replace {rtype = Expr, pos = SrcSpan {startLine = 1, startCol = 7, endLine
= 1, endCol = 10}, subts = [("x",SrcSpan {startLine = 1, startCol = 8, endLine =
1, endCol = 9})], orig = "x"}])]

> refactor test.hs --refact-file hlint.refact
foo = x

One of either the input file or --refact-file must be specified on the command line. If an input file is specified but not --refact-file then refactor will accept refactorings from stdin and vice versa.

The -i option can be specified to perform the refactoring inplace overwriting the input file. This option is ignored when input is read from stdin.

The -s option can be specified to perform a stepwise evaluation of the refact file. The user is prompted whether to perform each hint before it is performed.

The --pos option is intended to be used by tooling in order to specify which specific hint should be performed.

Refact Files

Refact files should be the result of show on a value of type [(String, [Refactoring SrcSpan])]. The string is a description of the refactoring, one description can have many associated refactoring steps.

Library Structure

The executable is provide so that libraries can use apply-refact without depending on the package. The implementation relies on ghc-exactprint which depends itself on GHC. A transitive dependancy that most developers wish to avoid!

Reporting Bugs

If the program produces a syntactically incorrect result then this is a bug. Please open an issue on the issue tracker with precise instructions about how to reproduce it.

  1. The input file
  2. The refact file
  3. The command used to invoke refactor

There are some known problems with CPP processing. If your library contains CPP directives other than #ifdef it is quite likely that the result will be unexpected.

Debugging

There are also two hidden flags which can be useful for debugging.

--debug

Outputs the GHC AST.

--roundtrip

Performs no refactoring operations on the file but is useful to test whether unexpected formatting is due to ghc-exactprint or the refactoring.