This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
GNATformat is an opinionated Ada source code formatter built on Prettier-Ada (a port of Prettier). It formats Ada code following the GNAT Coding Style guide. It ships as both a command-line tool and a library (used by the Ada Language Server).
# Build both the library (all three variants) and the binary
make all
# Build only the library (static, static-pic, relocatable)
make lib
# Build only the command-line binary
make bin
# Install (set PREFIX to desired location)
PREFIX=/usr/local make install
# Clean build artifacts (bin/, lib/, obj/)
make cleanBuild mode defaults to dev. Use BUILD_MODE=prod for optimized production builds.
GPR project files are in gnat/:
gnatformat_common.gpr— shared compiler switches (abstract project)gnatformat.gpr— the library project (sources fromsrc/)gnatformat_driver.gpr— the binary project; builds two Mains, thegnatformatbinary (sources fromsrc/formatters/ada/) and the standalonegit-gnatformatsubcommand wrapper (src/formatters/git/git_format.adb). The wrapper references no library units, so even though the projectwiths the library it links to ~1MB rather than a ~57MB copy ofgnatformat.
# Run the full testsuite
make test
# Run a specific test by directory path
python testsuite/testsuite.py testsuite/tests/path/to/test
# Rewrite test baselines to match current output
python testsuite/testsuite.py -r
# Run with Valgrind
python testsuite/testsuite.py --valgrindTests use the e3-testsuite framework. Each test
directory contains a test.yaml (driver config and args) and a test.out (expected output
baseline). Install test deps with pip install -r requirements-dev.txt.
The public library API lives in src/:
gnatformat.ads— root package; defines version constants and theGnatformat_Tracehandlegnatformat-configuration.ads/.adb—Format_Options_Type(width, indentation, charset, end-of-line, keyword casing, ignore);Format_Options_Builder_Typefor constructing options;From_Projectto read options from a GPR2 project'spackage Format;Load_Unparsing_Configurationfor formatting rulesgnatformat-formatting.ads/.adb— coreFormatandRange_Formatfunctions; takes anAnalysis_Unit+Format_Options_Typeand returns formatted text or aFormatting_Edit_Typegnatformat-edits.ads/.adb—Text_Edit_Type/Formatting_Edit_Type/Formatting_Edits_Type;Apply_Editsto write edits to diskgnatformat-helpers.ads/.adb— internal formatting helpersgnatformat-utils.ads— genericOptionaltype used throughout
The CLI binary is assembled here:
gnatformat-ada_driver.adb— main entry point; parses CLI args, loads project, dispatches toFull_FormatorRange_Formatgnatformat-command_line.ads— CLI argument declarationsgnatformat-command_line-configuration.ads/.adb— maps CLI flags toFormat_Options_Typegnatformat-project.ads/.adb— GPR2 project loading and source discoverygnatformat-full_format.ads/.adb— formats all sources in a project treegnatformat-range_format.ads/.adb— formats a selection range within one source filegnatformat-abstract_writers.ads— writer interface (write formatted output)gnatformat-console_writers.ads/.adb— writer that outputs to stdout (--pipemode)gnatformat-file_writers.ads/.adb— writer that overwrites files in placegitdiff.ads/.adb— support for--git-diffmode (format only changed lines)
git_format.adb— a small, dependency-free executable installed asgit-gnatformatnext tognatformaton thePATH, so Git exposes it as thegit gnatformatsubcommand. It translatesgit gnatformat [<base-commit>] [<extra args>]intognatformat --gitdiff <base-commit> [<extra args>](defaulting the base toHEAD), locates the siblinggnatformatbinary, spawns it, and forwards its exit status. It is a second Main ofgnatformat_driver.gpr; because it references no library units the linker pulls in nothing fromgnatformat.gpr, so the wrapper stays ~1MB instead of being a ~57MB copy of the formatter.
Formatting options can be set in a project file under package Format:
package Format is
for Width use "100";
for Indentation use "4";
for Indentation_Kind use "spaces"; -- or "tabs"
for Indentation_Continuation use "2";
for End_Of_Line use "lf"; -- or "crlf"
for Charset use "utf-8";
for Keyword_Casing use "lower"; -- or "upper" or "keep"
for Ignore use "ignore.txt";
end Format;Attributes can be indexed by language ("Ada") or by individual source filename.
The repo uses pre-commit for auto-formatting. The local hook runs gnatformat_edge on .ads/.adb
files (excluding testsuite), and black on .py files. Install with pre-commit install.