JavaScript Code
Formatting with prettier
Christopher "vjeux" Chedeau
const jsxWhitespace = options.singleQuote ? ifBreak("{' '}", " ") : ifBreak('{" "}', " ");



const multiLineElem = group(concat([ 

openingLines, 

indent(options.tabWidth,group(concat(childrenGroupedByLine), { shouldBreak: true })), 

hardline, 

closingLines 

]));
const jsxWhitespace = options.singleQuote ? ifBreak("{' '}", " ") : ifBreak('{" "}', " ");



const multiLineElem = group(concat([ 

openingLines, 

indent(options.tabWidth,group(concat(childrenGroupedByLine), { shouldBreak: true })), 

hardline, 

closingLines 

]));
const jsxWhitespace = options.singleQuote 

? ifBreak("{' '}", " ") 

: ifBreak('{" "}', " "); 



const multiLineElem = group( 

concat([ 

openingLines, 

indent( 

options.tabWidth, 

group(concat(childrenGroupedByLine), { shouldBreak: true })

), 

hardline, 

closingLines 

]) 

);
Technical People
"The Hardest Program
I've Ever Written"
-- dartfmt author
call(a, b, c)
call(a, b, c)
call(
a,
b,
c)
Hug last paren
call(a, b, c)
call(
a,
b,
c)
Hug last paren
call(a,
b,
c)
Align paren
call(a, b, c)
call(
a,
b,
c
)
call(
a,
b,
c)
Hug last paren Facebook style
call(a,
b,
c)
Align paren
If it fits in one line, stay in one line
Rule #1
call(call(a, b, c), b, c)
call(call(a, b, c), b, c)
call(call(
a,
b,
c
), b, c)
Break Inner
call(call(a, b, c), b, c)
call(
call(a, b, c),
b,
c
)
Break Outer
call(call(
a,
b,
c
), b, c)
Break Inner
call(call(a, b, c), b, c)
call(
call(a, b, c),
b,
c
)
call(
call(
a,
b,
c
),
b,
c
)
Break Outer Break Both
call(call(
a,
b,
c
), b, c)
Break Inner
Always break the outer one first
Rule #2
call(a, b, c)
call(
a,
b,
c
)
group indent ifBreak
call(a, b, c)
group('call(', indent(ifBreak('n'), 

'a,', ifBreak('n', '░'), 

'b,', ifBreak('n', '░'), 

'c', ifBreak('n') 

), ')')
call(
a,
b,
c
)
call( indent( n 

a, n 

b, n

c n 

) )
call(indent(n 

a,n 

b,n

cn 

))
call(

a,

b,

c

)
group('call(', indent(ifBreak('n'), 

'a,', ifBreak('n', '░'), 

'b,', ifBreak('n', '░'), 

'c', ifBreak('n') 

), ')')
call(

a, ░

b, ░

c

)
call(a,░b,░c)
call(a, b, c)




ExpressionStatement({ 

expression: CallExpression({ 

arguments: [ 

Identifier("a"), 

Identifier("b"), 

Identifier("c"), 

], 

}), 

})
Text AST IR Text
Making a pretty printer is easy

Making a pretty printer is easy

Making a good pretty printer is hard
call(
a,
b,
function() {



}
)
call(a, b, function() {



})
call(function() {}, function() {



})
call(
function() {},
function() {}
)
(╯°□°)╯︵ ┻━┻
items 

.map(() => {}) 

.filter(() => {})
Object 

.keys(items) 

.map(() => {}) 

.filter(() => {})
Object.keys(items) 

.map(() => {}) 

.filter(() => {})
<div 

{...a === null ? b : c}

/>
<div 

{...(a === null ? b : c)}

/>
a && b || c && d
(a && b) || (c && d)
a

? <div> 

... 

</div>

: null
Without paren
a 

? ( 

<div> 

... 

</div> 

) : null
With paren
With paren
Without paren
With paren
People
time find html/js/ -name '*.js' |

xargs -n 1000 -P24 prettier



real 3m26s
I can't push it on people
people have to pull it themselves
Rule #1
Generate Buzz
First experience using prettier
const jsxWhitespace = options.singleQuote ? ifBreak("{' '}", " ") : ifBreak('{" "}', " ");
It's a journey that takes time
Rule #2
cmd-shift-c

JavaScript Code Formatting With Prettier by Christopher Chedeau