Spacerat / format-blocks

A Python library for building code formatters.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Format Blocks

Format Blocks is a Python library for building code formatters.

Usage

Format Blocks provides a number of 'block' objects which know how to arrange text in various ways, such as LineBlock which arranges elements on one line, and StackBlock which stacks them across lines, and WrapBlock which wraps inserts line breaks at the margin.

However, the most import block is ChoiceBlock. ChoiceBlock accepts multiple formatting options, and allows for the solver to pick the choices which minimize the overall formatting cost.

See the tests for some examples!

Origins

Format Blocks is a fork of the guts of Google's R Formatter, rfmt. Rfmt was structured as a formatting library with an R implementation, almost entirely decoupled. To create Format Blocks, I just did some final decoupling, then polished up the code and wrote some extra features and tests.

About

A Python library for building code formatters.

License:Apache License 2.0


Languages

Language:Python 99.2%Language:Shell 0.8%