Skip to content

Commit

Permalink
fix: dotnet format no longer adds all files to git (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters authored Apr 14, 2024
1 parent be4401b commit affbdfe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ indent_style = space
tab_width = 4

# New line preferences
end_of_line = crlf
end_of_line = lf
insert_final_newline = true

#### .NET Coding Conventions ####
Expand Down Expand Up @@ -261,4 +261,5 @@ dotnet_naming_style.prefix_underscore.required_prefix = _
# Use underscores for private fields
dotnet_naming_rule.private_fields_with_underscore.symbols = private_fields
dotnet_naming_rule.private_fields_with_underscore.style = prefix_underscore
dotnet_naming_rule.private_fields_with_underscore.severity = warning
dotnet_naming_rule.private_fields_with_underscore.severity = warning

6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Auto detect text files and perform LF normalization
*.cs text diff=csharp eol=lf
*.cshtml text diff=html eol=lf
*.csx text diff=csharp eol=lf
*.sln text eol=lf
*.csproj text eol=lf
26 changes: 23 additions & 3 deletions .husky/pre-commit
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
#!/bin/sh

# Boilerplate husky
. "$(dirname "$0")/_/husky.sh"

dotnet format -v diag
# Find all c# related staged files, before doing anything
FILES_TO_BE_FORMATTED=$(git diff --staged --name-only | grep -E '\.(cs|csproj|sln)$' || echo '')

if [ -z $FILES_TO_BE_FORMATTED ]; then
echo "No .NET files to format, skipping dotnet format..."
exit 0
fi

echo "Files to be formatted:"
for file in $FILES_TO_BE_FORMATTED; do
echo " - $file"
done
echo "" # new-line for clarity

# Format c# related staged files only
echo $FILES_TO_BE_FORMATTED | xargs dotnet format -v diag Aplib.Net.sln --include

# Add all formatted files again, to add changed files
echo $FILES_TO_BE_FORMATTED | xargs git add

echo -e "\nDone formatting files!\nCheck the log to find out if files have changed.\n"

# Add any changes made by dotnet format to the commit
git add .

0 comments on commit affbdfe

Please sign in to comment.