Skip to content
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

Adding publicAPI, bannedApi, and Async analyzers #136

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
24 changes: 21 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ insert_final_newline = true
indent_style = space
indent_size = 4
dotnet_diagnostic.CA1308.severity=warning
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
end_of_line = crlf
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_diagnostic.RS0026.severity = suggestion
dotnet_diagnostic.RS0027.severity = suggestion

[project.json]
indent_size = 2
Expand Down Expand Up @@ -52,7 +61,7 @@ dotnet_style_predefined_type_for_member_access = true:suggestion
# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style

dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const
Expand All @@ -62,7 +71,7 @@ dotnet_naming_style.pascal_case_style.capitalization = pascal_case
# static fields should have s_ prefix
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style

dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
Expand All @@ -73,7 +82,7 @@ dotnet_naming_style.static_prefix_style.capitalization = camel_case
# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style

dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
Expand Down Expand Up @@ -532,6 +541,15 @@ dotnet_diagnostic.SA1642.severity = none

## SA1649: File name should match first type name
dotnet_diagnostic.SA1649.severity = none
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
#########################################################
#########################################################

Expand Down
40 changes: 37 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@
<LangVersion>12</LangVersion>
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>5.0.0</PackageValidationBaselineVersion>
</PropertyGroup>
<BannedApiAnalyzersVersion>3.3.4</BannedApiAnalyzersVersion>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alignment is off

<MicrosoftCodeAnalysisPublicApiAnalyzers>3.3.4</MicrosoftCodeAnalysisPublicApiAnalyzers>
<MicrosoftCodeAnalysisNetAnalyzersVersion>8.0.0</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftInternalAnalyzersVersion>2.9.7</MicrosoftInternalAnalyzersVersion>
</PropertyGroup>

<!-- This step doesn't build on our Linux pipeline. -->
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<EnforcePublicApiAnalyzer>true</EnforcePublicApiAnalyzer>
</PropertyGroup>

<PropertyGroup Label="Source Link">
<PropertyGroup Label="Source Link">
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<!-- Build symbol package (.snupkg) to distribute the PDB containing Source Link -->
Expand All @@ -39,7 +48,8 @@
<!-- The MSAL.snk has both private and public keys -->
<DelaySign>false</DelaySign>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify a bit if we don't want to have opt outs. These can go, and the conditions in the item groups can go.

<EnforceThreadingAnalyzers>true</EnforceThreadingAnalyzers>
</PropertyGroup>

<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
Expand All @@ -60,4 +70,28 @@
<ItemGroup Label="Build Tools" Condition="$([MSBuild]::IsOsPlatform('Windows'))">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

<!-- Dont run analyzers on notargets projects. -->
<ItemGroup Condition="'$(UsingMicrosoftNoTargetsSdk)' != 'true'">
<!-- PrivateAssets="All" is on these packages to ensure they're development dependencies
and aren't included as transitionary dependencies to package consumers.
For clarity, without PrivateAssets marked here, anyone consuming Microsoft.Identity.ServiceEssentials
would also be forced to install these dependencies. PrivateAssets avoids this problem. -->
<PackageReference Include="Microsoft.Internal.Analyzers" Version="$(MicrosoftInternalAnalyzersVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(EnforceThreadingAnalyzers)' == 'true'">
<!-- Protects against sync-over-async: https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/index.md. -->
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(MicrosoftCodeAnalysisPublicApiAnalyzers)" Condition="'$(EnforcePublicApiAnalyzer)' == 'true'">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions Microsoft.Identity.Abstractions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Identity.Abstract
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{97E0DF27-D88E-453A-AFF6-3B656AB8F46B}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
NuGet.config = NuGet.config
README.md = README.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public partial interface IDownstreamApi
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> GetForUserAsync<TOutput>(
Expand Down Expand Up @@ -88,7 +88,7 @@ public partial interface IDownstreamApi
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> GetForUserAsync<TInput, TOutput>(
Expand Down Expand Up @@ -122,7 +122,7 @@ public partial interface IDownstreamApi
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> GetForAppAsync<TOutput>(
Expand Down Expand Up @@ -157,7 +157,7 @@ public partial interface IDownstreamApi
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> GetForAppAsync<TInput, TOutput>(
Expand Down Expand Up @@ -195,7 +195,7 @@ public partial interface IDownstreamApi
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task PostForUserAsync<TInput>(
Expand Down Expand Up @@ -235,7 +235,7 @@ public Task PostForUserAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> PostForUserAsync<TInput, TOutput>(
Expand Down Expand Up @@ -271,7 +271,7 @@ public Task PostForUserAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task PostForAppAsync<TInput>(
Expand Down Expand Up @@ -307,7 +307,7 @@ public Task PostForAppAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> PostForAppAsync<TInput, TOutput>(
Expand Down Expand Up @@ -345,7 +345,7 @@ public Task PostForAppAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task PutForUserAsync<TInput>(
Expand Down Expand Up @@ -385,7 +385,7 @@ public Task PutForUserAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> PutForUserAsync<TInput, TOutput>(
Expand Down Expand Up @@ -421,7 +421,7 @@ public Task PutForUserAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task PutForAppAsync<TInput>(
Expand Down Expand Up @@ -457,7 +457,7 @@ public Task PutForAppAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> PutForAppAsync<TInput, TOutput>(
Expand Down Expand Up @@ -497,7 +497,7 @@ public Task PutForAppAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task PatchForUserAsync<TInput>(
Expand Down Expand Up @@ -537,7 +537,7 @@ public Task PatchForUserAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> PatchForUserAsync<TInput, TOutput>(
Expand Down Expand Up @@ -573,7 +573,7 @@ public Task PatchForUserAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task PatchForAppAsync<TInput>(
Expand Down Expand Up @@ -609,7 +609,7 @@ public Task PatchForAppAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> PatchForAppAsync<TInput, TOutput>(
Expand Down Expand Up @@ -649,7 +649,7 @@ public Task PatchForAppAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task DeleteForUserAsync<TInput>(
Expand Down Expand Up @@ -689,7 +689,7 @@ public Task DeleteForUserAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> DeleteForUserAsync<TInput, TOutput>(
Expand Down Expand Up @@ -725,7 +725,7 @@ public Task DeleteForUserAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task DeleteForAppAsync<TInput>(
Expand Down Expand Up @@ -761,7 +761,7 @@ public Task DeleteForAppAsync<TInput>(
/// });
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
public Task<TOutput?> DeleteForAppAsync<TInput, TOutput>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace Microsoft.Identity.Abstractions
/// </code>
/// </example>
<# if (framework != "net8"){ #>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
Copy link
Contributor Author

@jmprieur jmprieur Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't build for NET6.0 any longer.

[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
<# } #>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Task<HttpResponseMessage> CallApiForAppAsync(
/// }
/// </code>
/// </example>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
Task<TOutput?> CallApiForUserAsync<TInput, TOutput>(
Expand All @@ -186,7 +186,7 @@ Task<HttpResponseMessage> CallApiForAppAsync(
/// will find the user from the HttpContext.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The value returned by the downstream web API.</returns>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
Task<TOutput?> CallApiForUserAsync<TOutput>(
Expand All @@ -210,7 +210,7 @@ Task<HttpResponseMessage> CallApiForAppAsync(
/// by <paramref name="serviceName"/>.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The value returned by the downstream web API.</returns>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
Task<TOutput?> CallApiForAppAsync<TInput, TOutput>(
Expand All @@ -232,7 +232,7 @@ Task<HttpResponseMessage> CallApiForAppAsync(
/// by <paramref name="serviceName"/>.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The value returned by the downstream web API.</returns>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("This method's implementations also use generic types and are not trim-friendly.")]
#endif
Task<TOutput?> CallApiForAppAsync<TOutput>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@
<DependentUpon>IDownstreamApi.HttpMethods.tt</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt" />
</ItemGroup>

</Project>
Loading
Loading