Language reference · section 28
28. Formatter
pin fmt gives every file one layout. It has no options.
Feature: Formatter
Scenario: pin fmt formats a file in place
Given any pin file
When the author runs pin fmt file.pin
Then the file is formatted in place
Scenario: pin fmt --check fails when a file would change
Given a file that is not formatted
When the author runs pin fmt --check file.pin
Then the command exits with 1
Scenario: pin fmt - reads stdin and writes stdout
Given text on stdin
When the author runs pin fmt -
Then the formatted text is written to stdout
Scenario: The formatter refuses code that does not parse
Given code with a syntax error
When the author runs pin fmt
Then the formatter does not change the file
Scenario: The formatter does not change what the program means
Given any file
When the formatter runs
Then the output has the same tokens and comments as the input
Layout rules:
- Indentation is two spaces per block level. A continued line is indented one level deeper than the statement it continues.
- An operator has a space on each side. Brackets, commas, dots, and ranges have no space inside them. Object braces have one space inside:
{ a: 1 }. - A unary minus and a decorator attach to what follows them.
- A statement with two or more top-level
|>breaks before each stage after the first, one level deeper. A chain with a comment is left as written. - A statement that acts (a call or a
return) right after bindings gets a blank line before it. - One blank line separates top-level declarations (functions, classes, decorated functions, exports) from what comes before and after them.
- Other blank lines are kept, collapsed to one. Blank lines at the start of a block are removed.
- Trailing whitespace is removed. The file ends with one newline.
message = " pin is fun "
|> clean
|> shout