Skip to content

KDABLabs/slint-pre-commit-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slint-pre-commit-hooks

Pre-commit hooks for formatting Slint UI files using slint-lsp.

Available Hooks

Hook ID Description
slint-format Formats .slint and .60 files in-place using slint-lsp format --inline

Quick Start

Prerequisites

  • pre-commit installed (pip install pre-commit or via your package manager)
  • A Rust toolchain (rustup.rs) — pre-commit uses it to build slint-lsp from crates.io

1. Add the hook to your project

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-format

2. Install the git hook

pre-commit install

3. Done!

The 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

Run Manually

Format all .slint files in your repo (without committing):

pre-commit run slint-format --all-files

Format specific files:

pre-commit run slint-format --files ui/app-window.slint ui/components.slint

Alternative: Local / System Hook

If 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.

How It Works

  1. language: rust tells pre-commit to bootstrap a Rust build environment.
  2. additional_dependencies: ['cli:slint-lsp:1.15.0'] installs the slint-lsp binary from crates.io via cargo install into an isolated pre-commit cache.
  3. On each commit, the hook runs slint-lsp format --inline on every staged .slint / .60 file.
  4. 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-lsp from source, which can take several minutes. Subsequent runs use the cached binary and are fast.

Configuration

Pin a specific slint-lsp version

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']

Limit to specific directories

hooks:
  - id: slint-format
    files: '^ui/.*\.(slint|60)$'

Exclude files

hooks:
  - id: slint-format
    exclude: 'generated/.*\.slint$'

Troubleshooting

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).

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages