Code Monkey home page Code Monkey logo

edent's Introduction

edent

Code indenter for Erlang.

Design Considerations

  • Uniformize indentation across multiple code bases.
  • Maintains user decisions related to formatting.
  • Dirt simple (someone else is working on a proper formatter).
  • Should clean up trailing whitespaces
  • Should be self-contained. Dependency on OTP is ok.

As a side-effect of keeping things stupid-simple, edent has one indentation style. There are currently no plans or desire to make it customizable.

If you see problems, then please create a PR containing a test with what the indentation should look like. Keep in mind that if your change is subjective in nature it will likely be denied. If that angers you, you can always fork and modify to suite your personal predilections.

Usage

The only dependency required to run this is OTP; any relatively recent version should be fine.

$ ./edent
usage: edent [-v] <input>...
       edent [-v] -o <output> <input>

The first form will overwrite each input file with their indented versions. This will be commonly used like this:

$ find . -name '*.erl' | xargs ./edent

The second form is mostly useful for testing and debugging where you want to not overwrite the orignal file. It's currently used for the test suite of edent.

Note that pre-commit hook is also available for git and expects edent to exist at the root of your repo.

Finally, the -v option exists for debugging edent and outputs internal debugging information.

Development

edent is a pretty simple escript so nothing too fancy is required to get up and running.

To run tests:

$ ./tests.sh
$ ./tests.sh <test>

The general idea of the tests, is that the files in the tests folder describe the expected behaviour of edent. The test harness will run edent on a file and diff the result against the original. A difference indicates a bug.

Otherwise, any changes should ideally be covered by a test because it's already pretty hard to keep track of how everything should line up so tests are the path to sanity.

Known bugs

  • erl_scan eats the \n character after a . character BUT NOT if there's any form of whitespace in between the two characters.

    1> erl_scan:string("a.\nb", 0, [return]).
    {ok,[{atom,0,a},{dot,0},{atom,1,b}],1}
    
    2> erl_scan:string("a. \nb", 0, [return]).
    {ok,[{atom,0,a},{dot,0},{white_space,0,"\n"},{atom,1,b}],1}

    Because of this behaviour, edent inserts an \n after each . so if you have trailing whitespaces then it's possible that edent will insert extra end-of-lines in your file. This might be fixable upstream, and I'll open an issue at some point.

  • There's a few known pieces of syntax that edent can't handle. These are documented in the hell.erl test cases. Hopefully these should be relatively rare in the wild.

  • edent is quite slow at the moment and I consider that a bug.

edent's People

Contributors

rattab avatar

Watchers

 avatar  avatar  avatar

Forkers

benrs

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.