ffmt
A fast, configurable Fortran formatter. Written in Rust. Installable via pip.
Installation
Or from source:
Usage
|
What it does
- Indentation -- scope-based indentation for all Fortran constructs
- Whitespace -- consistent spacing around operators, commas, colons, parentheses
- Keywords -- case normalization (
IF->if,ENDDO->end do) - Continuation lines -- normalized with proportional re-indentation
- Preprocessor -- Fypp (
#:if,#:for), OpenACC (!$acc), OpenMP (!$omp) handled correctly
Configuration
Create ffmt.toml or add [tool.ffmt] to pyproject.toml:
= 4
= "lower" # lower, upper, preserve
= true # enddo -> end do
[]
= true # ==, /=, <, <=, >, >=
= true # .and., .or., .not.
= true # binary +, -
= false # *, /
= false # **
= true # =
= true # ::
= true # space after comma
All options have sensible defaults -- most projects need no config file at all.
Preserved as-is
- String literals and inline expressions (
${...}$,@{...}@) - Comment contents and Doxygen alignment (
!<,!>,!!) - Continuation line structure
#ifdef/#endifblocks (no indentation change)
Editor integration
ffmt includes a built-in LSP server for real-time format-on-save:
VS Code
Vim/Neovim
autocmd BufWritePost *.fpp,*.f90 silent !ffmt %
" Or: set formatprg=ffmt\ -
Neovim (LSP)
vim..
CI integration
GitHub Actions
- uses: sbryngelson/ffmt@v0.1.0
with:
args: "--check src/"
pre-commit
repos:
- repo: https://github.com/sbryngelson/ffmt
rev: v0.1.0
hooks:
- id: ffmt
License
MIT