GithubHelp home page GithubHelp logo

rebar3_format's Introduction

rebar3_format

A rebar plugin for code formatting

Build

$ rebar3 compile

Use

Add the plugin to your rebar config:

{plugins, [rebar3_format]}

Then just call your plugin directly in an existing application:

$ rebar3 format

This will format every Erlang file under /src by default. You can specify the directory/file to format as following:

$ rebar3 format --files src/my_subdir/*.erl
$ rebar3 format --files src/other_subdir/my_file.erl
$ rebar3 format --files test/**/*.erl

To save the formatted files in a different directory you have to pass it as a parameter:

$ rebar3 format --output formatted/

Configuration

The plugin supports the following configuration options in the format section of rebar.config:

  • files ([file:filename_all()]):
    • List of wildcard patterns representing the files that will be formatted by default (i.e. when not using --files on command line).
    • The default value is ["src/**/*.?rl"]
  • encoding(none | epp:source_encoding()):
    • Encoding to use when writing files.
    • The default value is none.
  • paper(pos_integer()):
    • Specifies the preferred maximum number of characters on any line, including indentation.
    • The default value is 100.
  • ribbon(pos_integer()):
    • Specifies the preferred maximum number of characters on any line, not counting indentation.
    • The default value is 80.
  • break_indent(pos_integer()):
    • Specifies the preferred number of characters to use to indent a line that "breaks" from the previous one (for instance, a clause body after a clause head).
    • The default value is 4.
  • sub_indent(pos_integer()):
    • Specifies the preferred number of characters to use to indent a line that "follows" the current one (for instance, a long clause head or a long function application).
    • The default value is 2.
  • remove_tabs (boolean()):
    • Erlang's prettypr inserts a tab character each time it has to insert 8 spaces for indentation and that code is in a 100% unconfigurable/unreplaceable/unhookable function. If this setting is true, the formatter will turn those tabs into 8 spaces again.
    • The default value is true.
    • NOTE: We are aware that true is not the actual OTP default but... really? Who wants their code indented with a mixture of tabs and spaces? ๐Ÿ™ˆ

Per-File Configuration

You can tweak any of the options above for a particular file, using the format attribute in it, like this:

-format([{paper, 80}]).

Test

To test the plugin just run rebar3 test. It will essentially run rebar3 format inside test_app. Add modules with any "tricky" formatting you want to test_app/src, and push them to github including the after results. The after results can be tought as the expected output behaviour.

Contribute

To contribute to rebar3_format, please refer to CONTRIBUTING.

rebar3_format's People

Contributors

diegomanuel avatar juanbono avatar alanz avatar elbrujohalcon avatar msantos avatar

Watchers

James Cloos avatar  avatar

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.