TLDR Web Dev · ARTICLES & TUTORIALS
HOW TO WRITE A CODE FORMATTER
Summary from the TLDR Web Dev newsletter
This article is a detailed walkthrough in building a basic code formatter, with code examples along the way. To create a code formatter, first transform the code into an abstract syntax tree (AST) and then build a formatting tree using nodes that represent concepts like text, whitespace, and indentation. Traverse the formatting tree, rendering each node into the final formatted code.