Skip to content

MrLuje/dotnet-format-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Format-Hook

CI Tests Nuget

dotnet-format as a git pre-commit hook

Requirements

  • git
  • dotnet cli (>= 3.0)

How to install

  • VisualStudio
    • PackageManager : search for format-hook and install to your main csproj
    • PackageManager console : Install-Package format-hook
  • .NET CLI : dotnet add <!path to your csproj> package format-hook

Build you project, and you are done 👏

format-hook is a development dependency so it won't affect build artifacts 🚩

example precommit hook

How

Under the hood, this will :

  • checks for an available dotnet-format binary in PATH and install a local one if needed
  • configures git to use the newly created hooks folder at the root of your repository
  • adds the pre-commit hook that handles dotnet-format

Your git repository will looks like :

- .git
- hooks/
  - pre-commit
...
... rest of your repository

How to uninstall

  • remove format-hook nuget
  • delete .git/format-hook.enabled file
  • delete hooks folder
  • edit .git/config and remove the line : hooksPath = hooks

Configuration

You can configure the following properties by adding them on the csproj you installed format-hook :

Property Description Default Value
CI Prevent hook from being installed if true. Major CI systems set it to true by default false
HooksPath Folder to which hooks are configured hooks
DotnetFormatVersion dotnet-format version to install if missing 4.0.130203

Example

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <HooksPath>GitHook</HooksPath>
  </PropertyGroup>
</Project>

Supported frameworks

  • .Net Standard / .NET Core
  • Full Framework .NET

Tests

With powershell

Run ./scripts/tests.ps1

With act

docker build . -t act-dotnetformathook
act -P ubuntu-latest=act-dotnetformathook

Acknowledgments

https://commons.wikimedia.org/wiki/File:Breathe-format-indent-more.svg

https://github.com/Nagarian/dotnethooks

About

dotnet-format as a git pre-commit hook for your projects through nuget

Resources

License

Stars

Watchers

Forks