- code is formatted before committing (pre-commit hook)
- code meets quality standards before pushes (pre-push hook)
Installation
Installation is easiest using the Qlty CLI.- First Install Qlty.
- Run:
Pre-commit
The Git pre-commit hook runsqlty fmt on the files staged for the commit.
Pre-push
The Git pre-push hook will ensure that files are auto-formatted before pushing. If there are files that are formatted incorrectly, it will format them and generate a new commit. Due to the way Git works, when this occurs, you will need to rungit push again.
You can always run
git push --no-verify to skip the pre-push hook.Keeping slow plugins out of git hooks
Each hook tells Qlty which trigger is running. The pre-commit hook runsqlty fmt --trigger pre-commit, and the pre-push hook runs qlty check --trigger pre-push. A plugin runs on a trigger when its triggers list includes that trigger, or when it has no triggers list. See Triggers for the trigger each context uses.
There are two ways to keep a slow plugin out of your hooks:
- Limit the plugin’s triggers in
qlty.toml. This works with the installed hooks, with your own hook scripts, and with global hooks. - Skip the plugin with
--skipin a hook script for one repository.
Limit the plugin’s triggers
Inqlty.toml, give the plugin a triggers list without pre-commit or pre-push:
.qlty/qlty.toml
qlty githooks install, that’s all you need, because they pass --trigger for you. The plugin still runs when you run qlty check yourself and in Qlty Cloud analysis. To keep it running in the Qlty VS Code extension too, add ide to the list.
If you write your own hook script, pass --trigger with the hook’s name, as the installed hooks do, so triggers settings apply:
.git/hooks/pre-push
Skip the plugin in one repository’s hook
In a hook script for a single repository, you can add--skip with the plugin’s name:
.git/hooks/pre-push
--skip fails with Plugin not found when the plugin wouldn’t run anyway: it isn’t enabled, it’s disabled, its triggers leave out the hook’s trigger, or it has skip_upstream = true and the hook is pre-push. So don’t use --skip in a hook that runs in more than one repository. Use triggers instead. See check and fmt for the --trigger and --skip flags.
Global hooks
A global hook runs in every repository on your machine. Git uses global hooks whencore.hooksPath is set in your global Git config, for example with git config --global core.hooksPath ~/.git-hooks.
To run Qlty from a global hook:
- Call
qlty checkfrom your global hook script. Whencore.hooksPathis set, Git ignores each repository’s.git/hooksdirectory, so hooks fromqlty githooks installdon’t run. - Pass
--trigger pre-pushsotriggerssettings apply. - Keep slow plugins out with
triggersin each repository’sqlty.toml, not--skip.--skipfails in every repository that doesn’t enable the plugin. - Skip repositories where Qlty isn’t set up. There,
qlty checkexits with an error and blocks the push.
~/.git-hooks/pre-push