Coder Social home page Coder Social logo

apply-refact's Introduction

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.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.