Format Command¶
The format command rewrites supported Python template strings in place.
Supported formatter backends:
- HTML
- T-HTML
- JSON
- YAML / YML
- TOML
Unsupported embedded languages are left unchanged.
Basic Usage¶
# Format a single file
t-linter format file.py
# Format a directory recursively
t-linter format src/
# Default target is the current directory
t-linter format
# Override the formatter line length
t-linter format --line-length 100 file.py
Check Mode¶
Use --check to report files that would change without rewriting them:
Exit codes:
| Code | Meaning |
|---|---|
0 |
Formatting check succeeded with no changes needed |
1 |
--check found at least one file that would be reformatted |
2 |
Operational failure such as an unreadable file or invalid input |
Stdin¶
Use - to read a Python document from stdin:
When --stdin-filename is provided, format resolves pyproject.toml from that file's
parent directory. Without it, stdin formatting resolves config from the current working
directory.
Line Length¶
HTML and T-HTML formatting uses the following precedence. JSON, YAML, and TOML
formatters ignore line-length.
--line-lengthpyproject.tomltool.t-linter.line-length- default
80
Notes¶
formatrespectspyproject.tomlexcludes and.t-linterignore- explicit file operands must use the
.pyextension - formatting is atomic per file: on failure, the original file is left untouched