Skip to content

Commit 794e9bd

Browse files
Establish repository formatting baseline and enforcement
- normalize repository whitespace and formatting to the current .editorconfig baseline - add a pre-commit hook, hook installer, CI verification, and contributor guidance for formatting - tune .editorconfig and project files to avoid WinUI/XAML false positives and keep Visual Studio design-time loading working - fix WindowsPackageManager interop workspace loading for dotnet format
1 parent 0d094e4 commit 794e9bd

328 files changed

Lines changed: 21848 additions & 13898 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
src/UniGetUI.PackageEngine.Managers.Chocolatey/choco-cli/** linguist-vendored
1+
src/UniGetUI.PackageEngine.Managers.Chocolatey/choco-cli/** linguist-vendored
2+
.githooks/* text eol=lf

.githooks/pre-commit

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env sh
2+
3+
set -eu
4+
5+
repo_root=$(git rev-parse --show-toplevel)
6+
cd "$repo_root"
7+
8+
staged_files=$(git diff --cached --name-only --diff-filter=ACMR -- src | grep -E '\.(cs|csproj|props|targets|editorconfig|json|sln|slnx)$' || true)
9+
10+
if [ -z "$staged_files" ]; then
11+
exit 0
12+
fi
13+
14+
unstaged_files=$(git diff --name-only -- $staged_files || true)
15+
if [ -n "$unstaged_files" ]; then
16+
echo "pre-commit: relevant files have unstaged changes."
17+
echo "Stage or stash them before committing so dotnet format does not rewrite mixed content."
18+
printf '%s\n' "$unstaged_files"
19+
exit 1
20+
fi
21+
22+
if ! command -v dotnet >/dev/null 2>&1; then
23+
echo "pre-commit: dotnet CLI not found; skipping whitespace formatting."
24+
exit 0
25+
fi
26+
27+
echo "pre-commit: running dotnet format whitespace on staged src files"
28+
29+
# shellcheck disable=SC2086
30+
dotnet format whitespace src --folder --verbosity minimal --include $staged_files
31+
32+
if ! git diff --quiet -- $staged_files; then
33+
git add -- $staged_files
34+
echo "pre-commit: formatting updates were staged. Review them and run git commit again."
35+
exit 1
36+
fi
37+
38+
exit 0

.github/workflows/dotnet-test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ on:
55
paths:
66
- '**.cs'
77
- '**.csproj'
8+
- '**.props'
9+
- '**.targets'
810
- '**.sln'
11+
- 'src/.editorconfig'
912
- '.github/workflows/dotnet-test.yml'
1013

1114
pull_request:
1215
branches: [ "main" ]
1316
paths:
1417
- '**.cs'
1518
- '**.csproj'
19+
- '**.props'
20+
- '**.targets'
1621
- '**.sln'
22+
- 'src/.editorconfig'
1723
- '.github/workflows/dotnet-test.yml'
1824

1925
workflow_dispatch:
@@ -47,6 +53,13 @@ jobs:
4753
working-directory: src
4854
run: dotnet restore UniGetUI.sln
4955

56+
- name: Check whitespace formatting
57+
run: dotnet format whitespace src --folder --verify-no-changes --verbosity minimal
58+
59+
- name: Check code style formatting
60+
working-directory: src
61+
run: dotnet format style UniGetUI.sln --no-restore --verify-no-changes --verbosity minimal
62+
5063
- name: Run Tests
5164
working-directory: src
5265
run: dotnet test UniGetUI.sln --no-restore --verbosity q --nologo

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ Before reading: All of the rules below are guidelines, which means that they sho
3838
- Draft pull requests should be properly identified as [draft pull requests](https://github.blog/2019-02-14-introducing-draft-pull-requests/) to avoid confusion.
3939
- When modifying/coding, please follow the guidelines below:
4040

41+
## Formatting:
42+
- Run `pwsh ./scripts/install-git-hooks.ps1` once after cloning to enable the repository pre-commit hook.
43+
- The pre-commit hook runs `dotnet format whitespace src --folder` on staged files under `src` when the `dotnet` CLI is available, and stops the commit if it had to rewrite files so you can review the changes and commit again.
44+
- CI enforces whitespace formatting with `dotnet format whitespace src --folder --verify-no-changes` and code-style verification with `dotnet format style src/UniGetUI.sln --no-restore --verify-no-changes` in `.github/workflows/dotnet-test.yml`.
45+
- The pre-commit hook intentionally does not run `dotnet format style` because solution loading makes it take roughly the same time for one staged C# file as for the full solution.
46+
- If you want to check the same style rules locally before pushing, run `dotnet format style src/UniGetUI.sln --no-restore --verify-no-changes` from the repository root.
47+
- If you want to prepare a dedicated formatting-only commit, run `dotnet format whitespace src --folder` from the repository root.
48+
4149
## Coding:
4250
- As a repository standard, every function and variable name should use camelCase.
4351
- Correct usage: `updatesCount = 0`, `def searchForUpdates(packageManager):`

scripts/install-git-hooks.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
4+
5+
git -C $repoRoot config core.hooksPath .githooks
6+
7+
Write-Host 'Configured git hooks path to .githooks' -ForegroundColor Green
8+
Write-Host 'The pre-commit hook will run dotnet format whitespace on staged files under src.' -ForegroundColor Green

src/.editorconfig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ dotnet_diagnostic.CA2246.severity = warning
280280
dotnet_diagnostic.CA2249.severity = warning
281281

282282
# IDE0005: Remove unnecessary usings
283-
dotnet_diagnostic.IDE0005.severity = warning
283+
dotnet_diagnostic.IDE0005.severity = suggestion
284284

285285
# IDE0011: Curly braces to surround blocks of code
286286
dotnet_diagnostic.IDE0011.severity = warning
@@ -343,6 +343,15 @@ dotnet_diagnostic.IDE0200.severity = warning
343343
dotnet_style_allow_multiple_blank_lines_experimental = false
344344
dotnet_diagnostic.IDE2000.severity = warning
345345

346+
# WinUI code-behind relies on XAML-wired event handlers that Roslyn cannot
347+
# reliably see as C# references.
348+
[UniGetUI/**.cs]
349+
dotnet_diagnostic.IDE0051.severity = suggestion
350+
dotnet_diagnostic.IDE0060.severity = suggestion
351+
352+
[UniGetUI/Controls/SourceManager.xaml.cs]
353+
dotnet_diagnostic.IDE0044.severity = suggestion
354+
346355
###### End of EditorConfig from dotnet/aspnetcore repository
347356

348357
### Our rules

src/Directory.Build.props

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@
1717
</PropertyGroup>
1818

1919
<PropertyGroup>
20-
<BuildSharedWindowsTargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows')) == 'true' or '$(EnableWindowsTargeting)' == 'true'">true</BuildSharedWindowsTargetFrameworks>
21-
<SharedTargetFrameworks Condition="'$(BuildSharedWindowsTargetFrameworks)' == 'true'">$(PortableTargetFramework);$(WindowsTargetFramework)</SharedTargetFrameworks>
22-
<SharedTargetFrameworks Condition="'$(SharedTargetFrameworks)' == ''">$(PortableTargetFramework)</SharedTargetFrameworks>
20+
<BuildSharedWindowsTargetFrameworks
21+
Condition="$([MSBuild]::IsOSPlatform('Windows')) == 'true' or '$(EnableWindowsTargeting)' == 'true'"
22+
>true</BuildSharedWindowsTargetFrameworks
23+
>
24+
<SharedTargetFrameworks Condition="'$(BuildSharedWindowsTargetFrameworks)' == 'true'"
25+
>$(PortableTargetFramework);$(WindowsTargetFramework)</SharedTargetFrameworks
26+
>
27+
<SharedTargetFrameworks Condition="'$(SharedTargetFrameworks)' == ''"
28+
>$(PortableTargetFramework)</SharedTargetFrameworks
29+
>
2330
</PropertyGroup>
2431

2532
<PropertyGroup Condition="'$(TargetFramework)' == '' and '$(TargetFrameworks)' == ''">
@@ -31,7 +38,10 @@
3138
<WindowsSdkPackageVersion>10.0.26100.56</WindowsSdkPackageVersion>
3239
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
3340
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
34-
<RuntimeIdentifier Condition="'$(Platform)' != '' and '$(Platform)' != 'AnyCPU' and '$(Platform)' != 'Any CPU'">win-$(Platform)</RuntimeIdentifier>
41+
<RuntimeIdentifier
42+
Condition="'$(Platform)' != '' and '$(Platform)' != 'AnyCPU' and '$(Platform)' != 'Any CPU'"
43+
>win-$(Platform)</RuntimeIdentifier
44+
>
3545
</PropertyGroup>
3646

3747
<PropertyGroup>
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>$(WindowsTargetFramework)</TargetFramework>
5-
<TargetFrameworks />
6-
</PropertyGroup>
7-
8-
9-
2+
<PropertyGroup>
3+
<TargetFramework>$(WindowsTargetFramework)</TargetFramework>
4+
<TargetFrameworks />
5+
</PropertyGroup>
106
</Project>
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using System.Runtime.InteropServices;
1+
using System.Runtime.InteropServices;
22
using ExternalLibraries.Pickers.Guids;
33

44
namespace ExternalLibraries.Pickers.Classes;
55

66
// ---------------------------------------------------
77
// .NET classes representing runtime callable wrappers
8-
[ComImport,
9-
ClassInterface(ClassInterfaceType.None),
10-
TypeLibType(TypeLibTypeFlags.FCanCreate),
11-
Guid(CLSIDGuid.FileOpenDialog)]
12-
internal class FileOpenDialogRCW
13-
{
14-
}
8+
[
9+
ComImport,
10+
ClassInterface(ClassInterfaceType.None),
11+
TypeLibType(TypeLibTypeFlags.FCanCreate),
12+
Guid(CLSIDGuid.FileOpenDialog)
13+
]
14+
internal class FileOpenDialogRCW { }
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using System.Runtime.InteropServices;
1+
using System.Runtime.InteropServices;
22
using ExternalLibraries.Pickers.Guids;
33

44
namespace ExternalLibraries.Pickers.Classes;
55

66
// ---------------------------------------------------
77
// .NET classes representing runtime callable wrappers
8-
[ComImport,
9-
ClassInterface(ClassInterfaceType.None),
10-
TypeLibType(TypeLibTypeFlags.FCanCreate),
11-
Guid(CLSIDGuid.FileSaveDialog)]
12-
internal class FileSaveDialogRCW
13-
{
14-
}
8+
[
9+
ComImport,
10+
ClassInterface(ClassInterfaceType.None),
11+
TypeLibType(TypeLibTypeFlags.FCanCreate),
12+
Guid(CLSIDGuid.FileSaveDialog)
13+
]
14+
internal class FileSaveDialogRCW { }

0 commit comments

Comments
 (0)