JavaScript code reformatter.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
examples
lib
test
.gitignore
README.md
index.js
package.json

README.md

looks

Code reformatting tool for JavaScript

WARN: Not ready for dev or production use!

Before:

var y,x =1;

y=function (){
  return (13+1 ) / 2
}

Run:

./bin/looks airbnb index.js

After:

var x = 1,
    y;

y = function() {
  return (13 + 1) / 2;
};

Main Idea

looks allows programmers to implement codestyles.

Codestyle is a combination of transformer and printer.

Transformer does recast ast transformations.

Printer prints ast.

Implemented transformers

  • ComposedTransformer

    Allows to do ordered composition of transformers.

  • GatherDeclarations

    Gather all vars in function/module and place on top of function/module.

    Before:

    function f() {
      x = y;
      var a;
      var b = 1;
    }

    After:

    function f() {
      var a, b = 1;
      x = y;
    }
  • SortDeclarationsByInit

    Place declarators with init before declarations without init.

    Before

    function f() {
      var x, y = 1;
    }

    After

    function f() {
      var y = 1, x;
    }
  • SortBodyByPriority

    Sort function/module body by priority:

    • 'use strict';
    • Function Declarations
    • Variable Declarations
    • everything else

    Before

    function f() {
      a = b + 1;
      var i;
      function z() {}
    }

    After

    function f() {
      function z() {}
      var i;
      a = b + 1;
    }