-
-
Notifications
You must be signed in to change notification settings - Fork 238
Add optional pre-commit hook for code formatting #5178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
419f26e
539134b
9770082
aa396a3
aed5d9a
1c00577
d0f43cf
bff2d6c
d3acfd4
ff80f08
348ff62
cb7245a
17254ac
38f435d
a3f0dd5
d1f2687
2db003e
99bae81
ee1b527
1d08d13
b5e1c98
d604b31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| echo "🔍 Checking code formatting..." | ||
|
|
||
| if ! git diff --quiet; then | ||
| echo "⚠️ Skipping format check: unstaged changes present." | ||
| echo " Stage or stash all changes before committing to enable the format check." | ||
| exit 0 | ||
| fi | ||
|
|
||
| INCLUDE_ARGS=() | ||
| while IFS= read -r f; do | ||
| INCLUDE_ARGS+=(--include "$f") | ||
| done < <(git diff --cached --name-only --diff-filter=ACM | grep '\.cs$' || true) | ||
|
jamescrosswell marked this conversation as resolved.
jamescrosswell marked this conversation as resolved.
jamescrosswell marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: I wasn't sure if filter |
||
|
|
||
| if [ ${#INCLUDE_ARGS[@]} -eq 0 ]; then | ||
| echo "✅ No C# files staged." | ||
| exit 0 | ||
| fi | ||
|
|
||
| FORMAT_OUTPUT=$(dotnet format Sentry.slnx --no-restore \ | ||
| "${INCLUDE_ARGS[@]}" \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: great optimization ... |
||
| --exclude ./modules "./**/*OptionsSetup.cs" ./test/Sentry.Tests/AttributeReaderTests.cs 2>&1) || { | ||
| echo "" | ||
| echo "❌ dotnet format failed:" | ||
| echo "$FORMAT_OUTPUT" | ||
| echo "" | ||
| exit 1 | ||
| } | ||
|
|
||
| if ! git diff --quiet; then | ||
| echo "" | ||
| echo "❌ Code formatting issues found!" | ||
| echo "" | ||
| echo "Please stage the formatting fixes and commit again:" | ||
| echo "" | ||
| echo " git add -u" | ||
|
sentry-warden[bot] marked this conversation as resolved.
|
||
| echo " git commit" | ||
| echo "" | ||
| exit 1 | ||
| fi | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Autofix enables skip bypassHigh Severity After Reviewed by Cursor Bugbot for commit b5e1c98. Configure here.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intentional rather than a defect. The unstaged-changes guard exists specifically so |
||
|
|
||
| echo "✅ Code formatting looks good!" | ||
| exit 0 | ||
|
jamescrosswell marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,25 @@ public Task<int> AiUpdateAsync(GlobalOptions options = default!) | |
| return RunStepAsync("npx @sentry/dotagents install", "npx", "@sentry/dotagents install", options.DryRun); | ||
| } | ||
|
|
||
| [Command("setup-hooks", Description = "Configure git to use the repo's pre-commit hooks from .githooks/.")] | ||
| public Task<int> SetupHooksAsync(GlobalOptions options = default!) | ||
| { | ||
| Console.WriteLine("[dev] Configuring git hooks path to .githooks/"); | ||
| return RunStepAsync("git config core.hooksPath", "git", "config core.hooksPath .githooks", options.DryRun); | ||
|
jamescrosswell marked this conversation as resolved.
|
||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setup skips executable bitMedium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit b5e1c98. Configure here.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not applicable here — |
||
|
|
||
| [Command("remove-hooks", Description = "Restore default git hooks behaviour (stops using .githooks/).")] | ||
| public async Task<int> RemoveHooksAsync(GlobalOptions options = default!) | ||
| { | ||
| Console.WriteLine("[dev] Restoring default git hooks path"); | ||
| var exitCode = await RunStepAsync("git config --unset core.hooksPath", "git", "config --unset core.hooksPath", options.DryRun); | ||
|
|
||
| // git exits with code 5 when the key doesn't exist. That's already the | ||
| // desired end state, so treat it as success to keep remove-hooks idempotent | ||
| // (e.g. running it twice, or before setup-hooks). | ||
| return exitCode == 5 ? 0 : exitCode; | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| [Command("nrest", Description = "Restore the default CI solution.")] | ||
| public Task<int> SolutionRestoreAsync( | ||
| [Argument("solution", Description = "Solution file to restore. Defaults to platform-specific CI solution if omitted.")] string? solution = null, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Settings that apply only to test code under /test | ||
| # (kept here so diagnostic suppressions for tests are easy to find). | ||
|
|
||
| [*.cs] | ||
|
|
||
| # Disable AOT analyser for test files | ||
| dotnet_diagnostic.IL2026.severity = none | ||
| dotnet_diagnostic.IL2070.severity = none | ||
| dotnet_diagnostic.IL2075.severity = none | ||
| dotnet_diagnostic.IL2090.severity = none | ||
| dotnet_diagnostic.CA2255.severity = none | ||
|
|
||
| # This appears to be broken and results in false positives (causing dotnet format to delete valid test scenarios) | ||
| dotnet_diagnostic.xUnit1025.severity = none |


Uh oh!
There was an error while loading. Please reload this page.