Use sqlfmt CLI
mainsqlfmt is a command-line tool for formatting .sql and .sql.jinja files.
Warning: sqlfmt may occasionally break SQL syntax. It is highly recommended to run it only on files tracked by version control (e.g., git) so changes can be easily reverted.
# List all commands and options
sqlfmt --help
# Format all SQL files in the current directory and subdirectories
sqlfmt .
# Check if files are formatted without modifying them (exits with code 1 if unformatted)
sqlfmt --check .
# Show a diff of changes required to format files
sqlfmt --diff .
# Format code from standard input (stdin) and output to stdout
echo "select 1" | sqlfmt -