Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flpvsk/looks
JavaScript code reformatter.
https://github.com/flpvsk/looks
Last synced: about 2 months ago
JSON representation
JavaScript code reformatter.
- Host: GitHub
- URL: https://github.com/flpvsk/looks
- Owner: flpvsk
- Created: 2014-09-21T17:28:34.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-08T23:53:15.000Z (about 10 years ago)
- Last Synced: 2024-12-02T00:49:52.190Z (2 months ago)
- Language: JavaScript
- Size: 246 KB
- Stars: 11
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# looks
## Code reformatting tool for JavaScript
**WARN: Not ready for dev or production use!**
*Before:*
```js
var y,x =1;y=function (){
return (13+1 ) / 2
}
```*Run:*
```
./bin/looks airbnb index.js
```*After:*
```js
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](https://github.com/benjamn/recast) *ast*
transformations.*Printer* prints *ast*.
### Implemented transformers
- [ComposedTransformer](./lib/transformers/ComposedTransformer.js)
Allows to do ordered composition of *transformers*.
- [GatherDeclarations](./lib/transformers/GatherDeclarations.js)
Gather all `var`s in function/module and place on top of
function/module.*Before*:
```js
function f() {
x = y;
var a;
var b = 1;
}
```*After*:
```js
function f() {
var a, b = 1;
x = y;
}
```- [SortDeclarationsByInit](./lib/transformers/SortDeclarationsByInit.js)
Place declarators with init before declarations without init.
*Before*
```js
function f() {
var x, y = 1;
}
```*After*
```js
function f() {
var y = 1, x;
}
```- [SortBodyByPriority](./lib/transformers/SortBodyByPriority.js)
Sort function/module body by priority:
- `'use strict';`
- Function Declarations
- Variable Declarations
- everything else*Before*
```js
function f() {
a = b + 1;
var i;
function z() {}
}
```*After*
```js
function f() {
function z() {}
var i;
a = b + 1;
}
```