Skip to content

Commit

Permalink
Enable PublicApiAnalyzers (#2782)
Browse files Browse the repository at this point in the history
* Enable PublicApiAnalyzers

See: https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md

Remove apiCompat files.

Include internals as there are friend assemblies.

* Add mark-shipped.ps1

* update changes to internal api

---------

Co-authored-by: Keegan Caruso <[email protected]>
Co-authored-by: Westin Musser <[email protected]>
Co-authored-by: Westin Musser <[email protected]>
  • Loading branch information
4 people authored Oct 7, 2024
1 parent 83b7118 commit 492a823
Show file tree
Hide file tree
Showing 103 changed files with 5,891 additions and 81 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ csharp_space_between_square_brackets = false
dotnet_code_quality.ca1802.api_surface = private, internal
dotnet_code_quality.CA2208.api_surface = public

# https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md
dotnet_diagnostic.RS0051.severity = error
dotnet_diagnostic.RS0052.severity = error
dotnet_diagnostic.RS0053.severity = error
dotnet_diagnostic.RS0054.severity = error
dotnet_diagnostic.RS0055.severity = error
dotnet_diagnostic.RS0057.severity = error
dotnet_diagnostic.RS0058.severity = error
dotnet_diagnostic.RS0061.severity = error

# RS0030: Do not used banned APIs
dotnet_diagnostic.RS0030.severity = error

Expand Down Expand Up @@ -184,6 +194,9 @@ dotnet_diagnostic.CA1845.severity = warning
# CA1846: Prefer AsSpan over Substring
dotnet_diagnostic.CA1846.severity = warning

# RS0037: Enable tracking of nullability of reference types in the declared API
dotnet_diagnostic.RS0037.severity = silent

[{GlobalSuppressions.cs,TrimmingAttributes.cs}]
dotnet_diagnostic.IDE0073.severity = none

Expand Down
Empty file.
19 changes: 0 additions & 19 deletions Tools/apiCompat/baseline/ApiCompatBaseline.net461.txt

This file was deleted.

11 changes: 0 additions & 11 deletions Tools/apiCompat/baseline/ApiCompatBaseline.net462.txt

This file was deleted.

11 changes: 0 additions & 11 deletions Tools/apiCompat/baseline/ApiCompatBaseline.net472.txt

This file was deleted.

17 changes: 0 additions & 17 deletions Tools/apiCompat/baseline/ApiCompatBaseline.net6.0.txt

This file was deleted.

21 changes: 0 additions & 21 deletions Tools/apiCompat/baseline/ApiCompatBaseline.netstandard2.0.txt

This file was deleted.

44 changes: 44 additions & 0 deletions Tools/mark-shipped.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[CmdletBinding(PositionalBinding=$false)]
param ()

Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"

function MarkShipped([string]$dir) {
$shippedFilePath = Join-Path $dir "PublicAPI.Shipped.txt"
$shipped = @()
$shipped += Get-Content $shippedFilePath

$unshippedFilePath = Join-Path $dir "PublicAPI.Unshipped.txt"
$unshipped = Get-Content $unshippedFilePath
$removed = @()
$removedPrefix = "*REMOVED*";
Write-Host "Processing $dir"

foreach ($item in $unshipped) {
if ($item.Length -gt 0) {
if ($item.StartsWith($removedPrefix)) {
$item = $item.Substring($removedPrefix.Length)
$removed += $item
}
else {
$shipped += $item
}
}
}

$shipped | Sort-Object -Unique |Where-Object { -not $removed.Contains($_) } | Out-File $shippedFilePath -Encoding Ascii
Clear-Content $unshippedFilePath
}

try {
foreach ($file in Get-ChildItem -re -in "PublicApi.Shipped.txt") {
$dir = Split-Path -parent $file
MarkShipped $dir
}
}
catch {
Write-Host $_
Write-Host $_.Exception
exit 1
}
7 changes: 7 additions & 0 deletions build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 492a823

Please sign in to comment.