• Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    Haskell
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Refactor Haskell source files

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

apply-refact 0.13.x supports GHC 9.2 through 9.6; 0.12.x and 0.11.x support GHC 9.2 and 9.4; 0.10.x supports GHC 9.2; 0.9.x supports GHC 8.6 through 9.0.

Install

cabal install apply-refact

Alternatively, clone the repo and run cabal install.

You can also install from Nix:

nix-env -iA nixpkgs.haskellPackages.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.

Multiple -X options may be provided to specify additional default language pragmas which might affect parsing, such as -XLambdaCase or -XRankNTypes.

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.

Contributing

Contributions are welcome. You can run the tests via cabal test.

More Repositories

1

eventlog2html

Visualise eventlog events as a static webpage
Haskell
69
star
2

500-sql-haskell

A Haskell implementation of "Functional pearl: a SQL to C compiler in 500 lines of code"
Haskell
47
star
3

icfp2015-papers

Accepted papers for ICFP 2015
Python
46
star
4

hie-lsif

Haskell
32
star
5

hs-speedscope

Haskell
29
star
6

ghc-artefact-nix

Create environments with GHC HEAD artefacts
Nix
28
star
7

hlint-refactor-mode

Emacs bindings for hlint's --refactor option
Emacs Lisp
28
star
8

simple-language-client

A LSP client where events are powered by fsnotify and diagnostics displayed in a simple terminal interface
Haskell
26
star
9

old-ghc-nix

Old and New GHC
Nix
21
star
10

hashtag-coerce

A GHC source plugin which detects opportunities to use coerce
Haskell
17
star
11

ghcide-reflex

Experimental fork of ghcide which is reimplemented using the FRP library reflex
Haskell
17
star
12

rg-map

Make a map of all georeferenced maps on routegadget
JavaScript
14
star
13

haskell-nix-plugin

Plugin scaffolding for nixpkgs
Nix
11
star
14

plugin-constraint

Haskell
10
star
15

gitlab-triage

Haskell
10
star
16

hlint-refactor-vim

Vim Script
10
star
17

refact

Intermediary between ghc-exactprint and hlint
Haskell
9
star
18

servant-pandoc

Render a servant API to Pandoc's native representation
Haskell
9
star
19

graphmod-plugin

A source plugin reimplementation of graphmod
Haskell
9
star
20

impure-hygienic-combinators

Haskell
8
star
21

elaborator-reflection-haskell

Haskell
8
star
22

gperftools-ghc-example

Example of finding off-heap memory leaks in Haskell programs
Haskell
7
star
23

anonymous-records-benchmark

Haskell
5
star
24

funflow-nix

Utilities for writing flows with environments created by nix
Haskell
5
star
25

compilers

Haskell implementation of the compilers practical
C
5
star
26

lift-plugin

A plugin which does something very magical with Template Haskell's Lift type class
Haskell
4
star
27

blog

TeX
4
star
28

dyepack

Don't leave the premises with my closure
Haskell
4
star
29

mpickering.github.io

HTML
3
star
30

core-kythe

Haskell
3
star
31

hlint-refactor-atom

A atom package which provides bindings for the hlint --refactor option
CoffeeScript
3
star
32

reflex-ghc

A reflex reimplementation of ghcide
Haskell
3
star
33

generic-lens-benchmarks

Benchmarks from Generic Deriving of Generic Traversals
Haskell
3
star
34

paper-template

Template for papers
TeX
2
star
35

core-prof

Add cost centres after simplification
Haskell
2
star
36

legendary-train

A program which benefits from -flate-specialise
Haskell
2
star
37

probable-eureka

Haskell
2
star
38

three-level

A three stage program you definitely want to write
Haskell
2
star
39

core-prof-plugin

Add cost centres after optimisation
Haskell
2
star
40

example-core-plugin

How to set up a project to develop a plugin
Haskell
2
star
41

test-th-prof

How to profile a splice
Haskell
2
star
42

rtcwrao-benchmarks

Replacing type classes with records affects optimisation benchmarks
Haskell
2
star
43

tth-define-instances

Haskell
1
star
44

records

Fork of records
Haskell
1
star
45

ghc-compile-time

Haskell
1
star
46

musical-spork

Haskell
1
star
47

let-insert

Haskell
1
star
48

probable-tribble

Experiments combining staging and dynamic programming inc. histo and dynamorphisms
Haskell
1
star
49

haskell-indexer-nix

Nix
1
star
50

weak-ptr-spaceleak-cabal

Example cabal project suitable for using with gdb
Haskell
1
star
51

shiny-system

15524
Haskell
1
star
52

funflow-gis

An experiment using funflow for a GIS processing pipeline
Haskell
1
star
53

bucs-bot

Haskell
1
star
54

clt

Haskell
1
star
55

plugin-recompilation-test

Haskell
1
star
56

crispy-computing-machine

Haskell
1
star
57

trac-to-remarkup

Haskell
1
star
58

threepenny-utils

Missing functions from threepenny-gui
Haskell
1
star
59

test-repo

Haskell
1
star
60

kmp

From Jun Inoue - Supercompiling with Staging
OCaml
1
star
61

cabal-doctest-demo

Demo of using external commands to implement `cabal doctest`
Shell
1
star
62

eventlog-imgui

Haskell
1
star