This repo contains a collection of reusable lefthook configuration files for various languages and tools.
In order to use any of the hooks in this repo, please do the following:
-
Install lefthook.
-
In the root directory of your git repo, use
lefthook installto create alefthook.ymlfile. -
Edit the file to include the hooks from this repo that you want:
remotes: - git_url: <https://github.com/AjayKMehta/lefthook.git> configs: - hooks/pre-commit/<hook1> - hooks/pre-commit/<hook2> - hooks/pre-push/<hook1>
💡 All the hooks are located in
hooks/<hook-type>/<hook>. -
Install dependencies for any hooks of interest (see next section for details).
-
Run
lefthook installto install these hooks in your repo. You can uselefthook check-installandlefthook dumpto verify everything is installed and configured correctly.
- run-commitlint.yml: Requires commitlint to be installed.
- run-typos.yml: Uses typos to spellcheck commit messages.
- dotnet-clean.yml: Run
dotnet cleanafter checkout.
- restore-nuget.yml: Restore NuGet packages if any lock file changes.
- analyze-csharp.yml: This uses
dotnet formatto run analyzers on staged C# files. - format-csharp.yml: This uses
dotnet formatto check formatting of staged C# files. - lint-actions.yml: This requires actionlint to be installed.
- lint-docker.yml: This requires hadolint to be installed.
- lint-json.yml: This requires jsonlint to be installed. It removes duplicate keys and pretty prints JSON files.
- lint-markdown.yml: This requires markdownlint-cli2 to be installed.
- lint-toml.yml: This requires taplo to be installed.
- lint-vscode.yml: This requires jsonlint to be installed. It removes duplicate keys and sorts
settings.json. - lint-yaml.yml: This requires yamllint to be installed.
-
detect-secrets.yml: This requires gitleaks to be installed.
-
-
This ensures .NET code builds and all tests run successfully.
-
You can override the default build configuration (
Release) by adding this to your repo'slefthook-local.yml:templates: build_config: <New value>
👉 Assumes that there is a solution file at repo root.
-