A Python-based formatter for justfiles that enforces consistent style and formatting conventions.
- Consistent Indentation: Normalizes all recipe bodies to use spaces (default: 4 spaces)
- Quote Normalization: Converts quotes to a consistent style (double or single)
- Automatic Spacing: Ensures proper spacing around operators (
:=,=) - Alphabetical Sorting: Optional alphabetical sorting of recipes
- Blank Line Management: Maintains consistent spacing between recipes
- Configuration Support: Load settings from
justfmt.iniorpyproject.toml - Check Mode: Verify formatting without making changes (perfect for CI)
- Diff Mode: Preview changes before applying them
Install as a development dependency using uv:
uv add --dev justfmtOr with pip:
pip install justfmtFormat a justfile in place:
justfmtThis will format the justfile in the current directory using default settings.
Format a specific file:
justfmt path/to/justfileCheck if a file is formatted without modifying it:
justfmt --checkExit code will be 1 if formatting is needed, 0 if already formatted.
Show a diff of what would change:
justfmt --diffSort recipes alphabetically:
justfmt --sortOverride the quote style:
justfmt --quote-style single
justfmt --quote-style doubleSpecify a configuration file or directory:
justfmt --config /path/to/configCreate a justfmt.ini file in your project root:
[justfmt]
indent_spaces = 4
quote_style = double
sort_recipes = false
blank_lines_between_recipes = 1
ensure_trailing_newline = trueAdd a [tool.justfmt] section to your pyproject.toml:
[tool.justfmt]
indent_spaces = 4
quote_style = "double"
sort_recipes = false
blank_lines_between_recipes = 1
ensure_trailing_newline = true| Option | Type | Default | Description |
|---|---|---|---|
indent_spaces |
int | 4 | Number of spaces for indentation |
quote_style |
str | "double" | Quote style: "double" or "single" |
sort_recipes |
bool | false | Sort recipes alphabetically |
blank_lines_between_recipes |
int | 1 | Number of blank lines between recipes |
ensure_trailing_newline |
bool | true | Ensure file ends with newline |
All recipe bodies are normalized to use spaces (tabs are converted):
Before:
test:
echo "hello"
pytestAfter:
test:
echo "hello"
pytestQuotes are normalized to your preferred style (preserving mixed quotes when necessary):
Before (with quote_style = "double"):
test:
echo 'hello world'After:
test:
echo "hello world"Consistent spacing around operators:
Before:
auto:='auto'
MY_VAR:="value"After:
auto := "auto"
MY_VAR := "value"Alphabetically sort recipes while preserving comments:
Before:
zzz:
echo "last"
aaa:
echo "first"After (with --sort):
aaa:
echo "first"
zzz:
echo "last"Add to your .pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: justfmt
name: Format justfile
entry: justfmt
args: [--check]
language: system
files: justfile$Ensure that mise is installed. See mise installation guide.
sh setup.shjust testjust fmtjust validate