Git Product home page Git Product logo

ex_format's Introduction

ExFormat

Hex.pm

ExFormat formats Elixir source code according to a standard set of rules based on the elixir-style-guide. It tries its best to accommodate the user's intent by preserving intended layout and syntax. The documentation is available online.

Note: ExFormat is in alpha, hence the formatted output style is still in flux.

Requirements

  • Erlang/OTP 20
  • Mix v1.5.1

Installation

As ExFormat works best with the unreleased Elixir v1.6, it is recommended to download the prebuilt escript (which embeds Elixir v1.6 in itself) and run it as an executable.

mix escript.install https://github.com/uohzxela/ex_format/raw/master/ex_format

If you haven't done so already, consider adding ~/.mix/escripts directory to your PATH environment variable.

Usage

# Change directory to your Elixir project
cd to/your/elixir/project

# Formats all files that match each wildcard
ex_format lib/**/*.ex config/**/*.exs

Background info

For those who are curious, the formatter is created by following these steps:

  1. Parse source code into AST
  2. Augment the AST nodes with metadata such comments and line breaks
  3. Do a recursive descent on the AST starting from the topmost node
  4. Pattern match on each node, format it according to the style guide and continue to recurse down its children nodes

Hence, conceptually, this is a very simple formatter and is a good example of how pattern matching works in practice.

There are also contributions to Elixir tokenizer and parser to augment the AST with the necessary metadata for formatting, you can check these out here.

ex_format's People

Contributors

uohzxela avatar

Watchers

Frans Oilinki avatar James Cloos 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.