slang-format is an opinionated SystemVerilog formatter built on top of the
slang parser. It provides both a
standalone command-line tool and the slang::format CMake library target.
The formatter has its own version and release stream. Language servers and
other tools can pin this repository as a submodule and link it in-process,
while users can independently install a newer slang-format binary.
See GitHub releases for published versions and release notes.
See the documentation for installation, workflow integration, configuration, and embedding.
Format all Verilog and SystemVerilog files in a directory tree in place:
slang-format -i rtl/Configuration is discovered from .slang/format.json. See the
command reference,
configuration reference, and
formatting philosophy.
See validation for output checks and force
behavior, and formatting markers for skipping
individual declarations or statements.
Install slang-format on your PATH, then add this local hook to your
.pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: slang-format
name: slang-format
entry: slang-format
language: system
args: [-i]
files: '\.(sv|svh|v|vh)$'If you already have a repos list, append the hook's repo: local entry to it.
Enable the hook and format existing files with:
pre-commit install
pre-commit run slang-format --all-filesprek users can replace pre-commit with prek in
these commands. On commit, the hook formats staged Verilog and SystemVerilog
files in place, discovering .slang/format.json for each file. Review and stage
any formatting changes, then retry the commit. Files with input structural errors,
syntax-preservation failures, or idempotency failures are left unchanged without
failing the hook. Other errors, such as invalid configuration or file I/O errors,
still fail the hook. For a check-only hook that also fails on validation errors,
replace args: [-i] with args: [--check].
See DEVELOPING.md for development setup and CONTRIBUTING.md for contribution guidelines.
Licensed under the MIT License.