Pre-commit hooks for formatting Slint UI files using slint-lsp.
| Hook ID | Description |
|---|---|
slint-format |
Formats .slint and .60 files in-place using slint-lsp format --inline |
- pre-commit installed (
pip install pre-commitor via your package manager) - A Rust toolchain (rustup.rs) — pre-commit uses it to build
slint-lspfrom crates.io
Create or update .pre-commit-config.yaml in your repository root:
repos:
- repo: https://github.com/KDABLabs/slint-pre-commit-hooks
rev: v1.15.0
hooks:
- id: slint-formatpre-commit installThe hook will now run automatically on every git commit, formatting any staged .slint or .60 files. If a file changes, the commit is blocked so you can review and re-stage:
$ git commit -m "update UI"
Slint Format.............................................................Failed
- hook id: slint-format
- files were modified by this hook
$ git diff # review the formatting changes
$ git add -u && git commit # stage and retry
Format all .slint files in your repo (without committing):
pre-commit run slint-format --all-filesFormat specific files:
pre-commit run slint-format --files ui/app-window.slint ui/components.slintIf you already have slint-lsp installed (e.g. via cargo install slint-lsp) and prefer not to have pre-commit build it from source, use a local hook instead:
repos:
- repo: local
hooks:
- id: slint-format
name: Slint Format
entry: slint-lsp format --inline
language: system
files: '\.(slint|60)$'This requires slint-lsp to be in your $PATH. No version pinning or isolation is provided — you manage the tool version yourself.
language: rusttells pre-commit to bootstrap a Rust build environment.additional_dependencies: ['cli:slint-lsp:1.15.0']installs theslint-lspbinary from crates.io viacargo installinto an isolated pre-commit cache.- On each commit, the hook runs
slint-lsp format --inlineon every staged.slint/.60file. - If the formatter modifies a file, pre-commit detects the change and fails the commit, letting you review the diff before re-staging.
Note: The first run will compile
slint-lspfrom source, which can take several minutes. Subsequent runs use the cached binary and are fast.
Override additional_dependencies in your .pre-commit-config.yaml:
repos:
- repo: https://github.com/KDABLabs/slint-pre-commit-hooks
rev: v1.15.0
hooks:
- id: slint-format
additional_dependencies: ['cli:slint-lsp:1.15.0']hooks:
- id: slint-format
files: '^ui/.*\.(slint|60)$'hooks:
- id: slint-format
exclude: 'generated/.*\.slint$'Hook takes a long time on first run
This is expected — slint-lsp is compiled from source. After the first run, the binary is cached.
cargo not found
Ensure a Rust toolchain is installed: https://rustup.rs/
slint-lsp version mismatch
Override additional_dependencies to pin the version you need (see Configuration).
MIT