Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
399b014
fix: address StyleCop code quality issues
jbrinkman Jul 19, 2025
d615ea5
fix: add final newlines and fix whitespace issues
jbrinkman Jul 19, 2025
7e6121b
fix: update Taskfile.yml with correct platform detection syntax
jbrinkman Jul 19, 2025
906616d
fix: return 'Unknown' instead of empty string in ApiChange.GetMemberN…
jbrinkman Jul 19, 2025
75c61d9
fix: add file headers and fix StyleCop issues
jbrinkman Jul 19, 2025
bc59945
feat: add PowerShell scripts for file headers and newlines
jbrinkman Jul 19, 2025
e85c5fc
Fix StyleCop issues and add code quality tools
jbrinkman Jul 19, 2025
e490b9f
fix: resolve string.empty
jbrinkman Jul 19, 2025
4416a47
fix: resolve string.empty
jbrinkman Jul 19, 2025
a455f42
fix: SA1513
jbrinkman Jul 19, 2025
1d7eb26
fix: SA1518
jbrinkman Jul 19, 2025
fd30570
fix: remove extra blank lines
jbrinkman Jul 19, 2025
c167b29
fix: stylecop issues
jbrinkman Jul 19, 2025
6837055
fix: stylecop issues
jbrinkman Jul 19, 2025
5fa6165
fix: add missing blank lines for style consistency
jbrinkman Jul 19, 2025
c305105
fix: constructor
jbrinkman Jul 19, 2025
3ad7ea3
fix: improve formatting for type checks in BuildMethodSignature
jbrinkman Jul 19, 2025
6ac3886
fix: refactor configuration classes to improve validation and default…
jbrinkman Jul 19, 2025
45cc2b4
fix: reorder and restore WildcardToRegex method in ExclusionConfigura…
jbrinkman Jul 19, 2025
13064cf
fix: simplify type handling in BuildMethodSignature using switch expr…
jbrinkman Jul 19, 2025
2475aea
fix: ensure documentation file generation is enabled in project confi…
jbrinkman Jul 19, 2025
98d500a
fix: reorder and restore XML documentation for assembly loading metho…
jbrinkman Jul 19, 2025
fbb6f1c
fix: enhance XML documentation for enums in Enums.cs for clarity and …
jbrinkman Jul 19, 2025
058d505
fix: disable XML comment analysis in project configuration
jbrinkman Jul 19, 2025
28ddb19
fix: update coverlet.collector and coverlet.msbuild to version 6.0.4
jbrinkman Jul 19, 2025
c95ab2a
fix: remove .NET Outdated tool installation from code quality workflow
jbrinkman Jul 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
"dotnet-reportgenerator-globaltool": {
"version": "5.2.0",
"commands": ["reportgenerator"]
},
"dotnet-format": {
"version": "5.1.250801",
"commands": ["dotnet-format"]
},
"dotnet-outdated-tool": {
"version": "4.6.0",
"commands": ["dotnet-outdated"]
}
}
}
47 changes: 34 additions & 13 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{json,yml,yaml}]
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.cs]
# Disable specific rules
dotnet_diagnostic.SA1633.severity = none # File header
dotnet_diagnostic.SA1200.severity = none # Using directive placement
dotnet_diagnostic.SA1101.severity = none # Prefix local calls with this

# Enable all other StyleCop rules
dotnet_analyzer_diagnostic.category-StyleCop.CSharp.DocumentationRules.severity = warning
dotnet_analyzer_diagnostic.category-StyleCop.CSharp.LayoutRules.severity = warning
dotnet_analyzer_diagnostic.category-StyleCop.CSharp.MaintainabilityRules.severity = warning
dotnet_analyzer_diagnostic.category-StyleCop.CSharp.NamingRules.severity = warning
dotnet_analyzer_diagnostic.category-StyleCop.CSharp.OrderingRules.severity = warning
dotnet_analyzer_diagnostic.category-StyleCop.CSharp.ReadabilityRules.severity = warning
dotnet_analyzer_diagnostic.category-StyleCop.CSharp.SpacingRules.severity = warning
# SA1309: Field names should not begin with underscore
dotnet_diagnostic.SA1309.severity = none

# SA1200: Using directive should appear within a namespace declaration
dotnet_diagnostic.SA1200.severity = none

# SA1633: File should have header
dotnet_diagnostic.SA1633.severity = none

# SA1101: Prefix local calls with this
dotnet_diagnostic.SA1101.severity = none

# SA1413: Use trailing comma in multi-line initializers
dotnet_diagnostic.SA1413.severity = none

# SA0001: XML comment analysis is disabled
dotnet_diagnostic.SA0001.severity = none

# Enforce final newline
insert_final_newline = true
5 changes: 0 additions & 5 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,3 @@ jobs:

- name: Run code analysis
run: dotnet build --no-restore /p:EnforceCodeStyleInBuild=true /p:EnableNETAnalyzers=true /p:AnalysisLevel=latest /p:TreatWarningsAsErrors=true

- name: Run .NET Outdated
run: |
dotnet tool install --global dotnet-outdated-tool
dotnet outdated --version-lock Major
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 DotNet API Diff Project Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
68 changes: 58 additions & 10 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,23 @@ tasks:

coverage:view:
desc: Open coverage report in default browser
platforms:
windows:
cmds:
- cmd.exe /c start {{.COVERAGE_DIR}}/index.html
darwin:
cmds:
- open {{.COVERAGE_DIR}}/index.html
linux:
cmds:
- xdg-open {{.COVERAGE_DIR}}/index.html
cmds:
- |
{{if eq OS "windows"}}
cmd.exe /c start {{.COVERAGE_DIR}}/index.html
{{else if eq OS "darwin"}}
open {{.COVERAGE_DIR}}/index.html
{{else}}
xdg-open {{.COVERAGE_DIR}}/index.html
{{end}}

tools:install:
desc: Install required dotnet tools
cmds:
- dotnet new tool-manifest --force || true
- dotnet tool install dotnet-reportgenerator-globaltool --ignore-failed-sources --version 5.2.0
- dotnet tool install dotnet-format --ignore-failed-sources
- dotnet tool install dotnet-outdated-tool --ignore-failed-sources

tools:restore:
desc: Restore dotnet tools
Expand All @@ -104,12 +105,59 @@ tasks:
cmds:
- dotnet publish {{.PROJECT}} -c Release -o ./publish

code:format:
desc: Format code using dotnet-format
cmds:
- dotnet tool restore
- dotnet format

code:format:verify:
desc: Verify code formatting without making changes
cmds:
- dotnet tool restore
- dotnet format --verify-no-changes

code:analyze:
desc: Run code analysis with analyzers
cmds:
- dotnet build {{.SOLUTION}} --no-restore /p:EnforceCodeStyleInBuild=true /p:EnableNETAnalyzers=true /p:AnalysisLevel=latest /p:TreatWarningsAsErrors=true

code:outdated:
desc: Check for outdated NuGet packages
cmds:
- dotnet tool restore
- dotnet outdated --version-lock Major

code:analyzers:install:
desc: Install code analyzers to projects
cmds:
- dotnet add src/DotNetApiDiff/DotNetApiDiff.csproj package Microsoft.CodeAnalysis.NetAnalyzers
- dotnet add src/DotNetApiDiff/DotNetApiDiff.csproj package StyleCop.Analyzers
- dotnet add tests/DotNetApiDiff.Tests/DotNetApiDiff.Tests.csproj package Microsoft.CodeAnalysis.NetAnalyzers

code:quality:
desc: Run all code quality checks
cmds:
- task: code:format:verify
- task: code:analyze
- task: code:outdated

code:fix:stylecop:
desc: Run StyleCop fix scripts
cmds:
- powershell -ExecutionPolicy Bypass -File ./scripts/Fix-SA1513.ps1
- powershell -ExecutionPolicy Bypass -File ./scripts/Fix-ConstructorInitializers.ps1
- powershell -ExecutionPolicy Bypass -File ./scripts/Fix-ParameterFormatting.ps1
- powershell -ExecutionPolicy Bypass -File ./scripts/Fix-TrailingCommas.ps1
- powershell -ExecutionPolicy Bypass -File ./scripts/Add-FinalNewlines.ps1

ci:
desc: Run CI build and test sequence
cmds:
- task: deps:install
- task: clean
- task: restore
- task: code:quality
- task: build
- task: test
- task: coverage
30 changes: 30 additions & 0 deletions scripts/Add-FileHeaders.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Define the header
$header = "// Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT"

# Process files in the src directory
Get-ChildItem -Path "src" -Filter "*.cs" -Recurse | ForEach-Object {
$file = $_.FullName
$content = Get-Content -Path $file -Raw

# Check if the file already has the header
if (-not $content.Contains("SPDX Identifier: MIT")) {
# Add the header to the beginning of the file
$newContent = "$header`n$content"
Set-Content -Path $file -Value $newContent
Write-Host "Added header to $file"
}
}

# Process files in the tests directory
Get-ChildItem -Path "tests" -Filter "*.cs" -Recurse | ForEach-Object {
$file = $_.FullName
$content = Get-Content -Path $file -Raw

# Check if the file already has the header
if (-not $content.Contains("SPDX Identifier: MIT")) {
# Add the header to the beginning of the file
$newContent = "$header`n$content"
Set-Content -Path $file -Value $newContent
Write-Host "Added header to $file"
}
}
23 changes: 23 additions & 0 deletions scripts/Add-FinalNewlines.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Add-FinalNewlines.ps1
# Script to ensure all C# files end with a newline

# Process all C# files in the src directory
Get-ChildItem -Path "src" -Filter "*.cs" -Recurse | ForEach-Object {
$file = $_.FullName
Write-Host "Processing $file"

# Read file content
$content = Get-Content -Path $file -Raw

# Check if the file already ends with a newline
if (-not $content.EndsWith("`n")) {
# Add a newline to the end of the file
Add-Content -Path $file -Value "`n" -NoNewline
Write-Host "Added final newline to $file"
}
else {
Write-Host "File $file already ends with a newline"
}
}

Write-Host "Final newline fixes completed for all C# files in src directory"
75 changes: 75 additions & 0 deletions scripts/Find-StyleCopIssues.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Find-StyleCopIssues.ps1
# Script to identify files with specific StyleCop issues

# Define the StyleCop issues to look for
$styleCopIssues = @{
"SA1201" = "A property should not follow a method"
"SA1204" = "Static members should appear before non-static members"
"SA1202" = "'public' members should come before 'private' members"
"SA1128" = "Put constructor initializers on their own line"
"SA1413" = "Use trailing comma in multi-line initializers"
"SA1116" = "Parameters should begin on line after declaration when spanning multiple lines"
"SA1117" = "Parameters should all be placed on the same line or each parameter should be placed on its own line"
}

# Process all C# files in the src directory
$files = Get-ChildItem -Path "src" -Filter "*.cs" -Recurse

# Create a report of files with potential issues
$report = @{}

foreach ($file in $files) {
$content = Get-Content -Path $file.FullName -Raw
$issues = @()

# Check for SA1201: A property should not follow a method
if ($content -match "public\s+\w+\s+\w+\([^)]*\)[^{]*\{[^}]*\}\s*public\s+\w+\s+\w+\s*\{") {
$issues += "SA1201"
}

# Check for SA1204: Static members should appear before non-static members
if ($content -match "public\s+\w+\s+\w+[^{]*\{[^}]*\}\s*public\s+static\s+\w+\s+\w+") {
$issues += "SA1204"
}

# Check for SA1202: 'public' members should come before 'private' members
if ($content -match "private\s+\w+\s+\w+[^{]*\{[^}]*\}\s*public\s+\w+\s+\w+") {
$issues += "SA1202"
}

# Check for SA1128: Put constructor initializers on their own line
if ($content -match "public\s+\w+\([^)]*\)\s*:\s+\w+\(") {
$issues += "SA1128"
}

# Check for SA1413: Use trailing comma in multi-line initializers
if ($content -match "\{\s*\w+[^,\n]*\n[^,\n]*\n[^,\n]*\}") {
$issues += "SA1413"
}

# Check for SA1116: Parameters should begin on line after declaration when spanning multiple lines
if ($content -match "\w+\([^)\n]+\n[^)]+\)") {
$issues += "SA1116"
}

# Check for SA1117: Parameters should all be on same line or each on own line
if ($content -match "\w+\([^,\n]+,\s*\n[^,\n]+,[^,\n]+\)") {
$issues += "SA1117"
}

if ($issues.Count -gt 0) {
$report[$file.FullName] = $issues
}
}

# Output the report
Write-Host "Files with potential StyleCop issues:"
foreach ($file in $report.Keys) {
Write-Host "`n$file"
foreach ($issue in $report[$file]) {
Write-Host " - $issue: $($styleCopIssues[$issue])"
}
}

Write-Host "`nNote: This script uses simple pattern matching and may produce false positives or miss some issues."
Write-Host "Manual review is recommended for the identified files."
38 changes: 38 additions & 0 deletions scripts/Fix-ConstructorInitializers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Fix-ConstructorInitializers.ps1
# Script to fix StyleCop SA1128 issues: Put constructor initializers on their own line

function Repair-ConstructorInitializers {
param (
[string]$content
)

# Replace constructor initializers that are on the same line
# Find patterns like "public ClassName(params) : base(params)" and put the initializer on its own line
$pattern = "(\s+public\s+\w+\([^)]*\))\s*:\s*([^\r\n]+)"
$replacement = '$1' + "`r`n : `$2"
$content = [regex]::Replace($content, $pattern, $replacement)

return $content
}

# Process all C# files in the src directory
Get-ChildItem -Path "src" -Filter "*.cs" -Recurse | ForEach-Object {
$file = $_.FullName
Write-Host "Processing $file"

# Read file content
$content = Get-Content -Path $file -Raw

# Fix SA1128 issues
$content = Repair-ConstructorInitializers -content $content

# Write the fixed content back to the file
Set-Content -Path $file -Value $content -NoNewline

# Ensure file ends with newline
Add-Content -Path $file -Value "`n" -NoNewline

Write-Host "Fixed constructor initializer issues in $file"
}

Write-Host "Constructor initializer fixes completed for all C# files in src directory"
Loading
Loading