opa-fmt(1)
| Open Policy Agent(1) | Open Policy Agent(1) |
NAME
opa-fmt - Format Rego source files
SYNOPSIS
opa fmt [path [...]] [flags]
DESCRIPTION
Format Rego source files.
The 'fmt' command takes a Rego source file and outputs a reformatted version. If no file path is provided - this tool will use stdin. The format of the output is not defined specifically; whatever this tool outputs is considered correct format (with the exception of bugs).
If the '-w' option is supplied, the 'fmt' command will overwrite the source file instead of printing to stdout.
If the '-d' option is supplied, the 'fmt' command will output a diff between the original and formatted source.
If the '-l' option is supplied, the 'fmt' command will output the names of files that would change if formatted. The '-l' option will suppress any other output to stdout from the 'fmt' command.
If the '--fail' option is supplied, the 'fmt' command will return a non zero exit code if a file would be reformatted.
The 'fmt' command can be run in several compatibility modes for consuming and outputting different Rego versions:
- •
- opa fmt:
- v1 Rego is formatted to v1
- rego.v1/future.keywords imports are NOT removed
- rego.v1/future.keywords imports are NOT added if missing
- v0 rego is rejected
- •
- opa fmt --v0-compatible:
- v0 Rego is formatted to v0
- v1 Rego is rejected
- •
- opa fmt --v0-v1:
- v0 Rego is formatted to be compatible with v0 AND v1
- v1 Rego is rejected
- •
- opa fmt --v0-v1 --v1-compatible:
- v1 Rego is formatted to be compatible with v0 AND v1
- v0 Rego is rejected
OPTIONS
--capabilities="" set capabilities version or capabilities.json file path
--check-result[=true] assert that the formatted code is valid and can be successfully parsed
-d, --diff[=false] only display a diff of the changes
--drop-v0-imports[=false] drop v0 imports from the formatted code, such as 'rego.v1' and 'future.keywords'
--fail[=false] non zero exit code on reformat
-h, --help[=false] help for fmt
-l, --list[=false] list all files who would change when formatted
--v0-compatible[=false] opt-in to OPA features and behaviors prior to the OPA v1.0 release
--v0-v1[=false] format module(s) to be compatible with both Rego v0 and v1
-w, --write[=false] overwrite the original source file
SEE ALSO
opa(1)
| Oct 2026 |
