Skip to content

Commit

Permalink
Format staged C# files on commit (#346)
Browse files Browse the repository at this point in the history
* Format staged C# files on commit

* Fix path
  • Loading branch information
sailro authored Aug 29, 2024
1 parent cc78c30 commit 35890b3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"husky": {
"version": "0.7.1",
"commands": [
"husky"
]
}
}
}
22 changes: 22 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

## husky task runner examples -------------------
## Note : for local installation use 'dotnet' prefix. e.g. 'dotnet husky'

## run all tasks
#husky run

### run all tasks with group: 'group-name'
#husky run --group group-name

## run task with name: 'task-name'
#husky run --name task-name

## pass hook arguments to task
#husky run --args "$1" "$2"

## or put your custom commands -------------------
#echo 'Husky.Net is awesome!'

dotnet husky run
10 changes: 10 additions & 0 deletions .husky/task-runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tasks": [
{
"name": "dotnet-format-staged-files",
"command": "dotnet",
"args": ["format", "src/Microsoft.Unity.Analyzers.sln", "whitespace", "--verbosity", "quiet", "--include", "${staged}"],
"include": ["**/*.cs"]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@
</EmbeddedResource>
</ItemGroup>

<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High" />
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High" WorkingDirectory="../.." />
</Target>

</Project>

0 comments on commit 35890b3

Please sign in to comment.