Skip to content

Commit

Permalink
Merge pull request #19 from allegro/feature/remove-analyzers-references
Browse files Browse the repository at this point in the history
Feature/remove analyzers references
  • Loading branch information
rafalschmidt97 authored Feb 28, 2024
2 parents a36572d + bb4e8ef commit 0275794
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 50 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ To configure the SDK, the following properties can be added into `Directory.Buil
For `C#` only:

- `AllegroDotnetSdkEnableImplicitUsingsAdjustments` (default: true for C#) - add `System.Collections.Immutable` and remove `Microsoft.Extensions.Logging` and `System.Net.Http` implicit usings.
- `UseAllegroDotnetSdkDefaultAnalyzers` (default: true for C# when no CPM) - reference and configure several external analyzers - StyleCop, AsyncFixer, Meziantou.
- `AllegroDotnetSdkEnableAsyncFixer` (default: `UseAllegroDotnetSdkDefaultAnalyzers`) - references AsyncFixer package.
- `AllegroDotnetSdkEnableMeziantou` (default: `UseAllegroDotnetSdkDefaultAnalyzers`) - references Meziantou.Analyzers package.
- `AllegroDotnetSdkEnableStyleCop` (default: `UseAllegroDotnetSdkDefaultAnalyzers`) - references StyleCop.Analyzers package and a preset `stylecop.json`.
- `AllegroDotnetSdkEnableStyleCopConfig` (default: true for C#) - references a preset `stylecop.json`.

Configure in `Directory.Build.props` - repo wide:

Expand All @@ -76,7 +73,7 @@ Configure in `Directory.Build.props` - repo wide:
<!-- The line below disables nullable reference types -->
<Nullable>disable</Nullable>
<!-- The line below disables the StyleCop -->
<AllegroDotnetSdkEnableStyleCop>false</AllegroDotnetSdkEnableStyleCop>
<AllegroDotnetSdkEnableStyleCopConfig>false</AllegroDotnetSdkEnableStyleCopConfig>
</PropertyGroup>

</Project>
Expand All @@ -95,6 +92,24 @@ Configure in `*.csproj` - project settings:
</Project>
```

## Analyzers

This SDK provides some default configuration (rules severity) for selected analyzers: StyleCop, Meziantou and AsyncFixer. It doesn't actually reference them. Avoiding direct references ensures that developers can seamlessly apply and update analyzers without being tied to specific versions.

To add analyzers, include the following in your `Directory.Build.props` or `Directory.Packages.props` file:

```xml
<Project>
<!-- ... -->
<ItemGroup>
<GlobalPackageReference Include="AsyncFixer" Version="1.6.0"/>
<GlobalPackageReference Include="Meziantou.Analyzer" Version="1.0.758"/>
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435"/>
</ItemGroup>
<!-- ... -->
</Project>
```

## Editor config

The SDK contains a global analyzer config file containing the default configuration for various analyzers and formatters.
Expand Down
4 changes: 2 additions & 2 deletions src/Allegro.DotnetSdk/Allegro.DotnetSdk.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.Build.NoTargets">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<PackageVersion>2.1.1</PackageVersion>
<TargetFramework>net8.0</TargetFramework>
<PackageVersion>2.2.0</PackageVersion>
<IsPackable>true</IsPackable>
<DevelopmentDependency>true</DevelopmentDependency>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
27 changes: 0 additions & 27 deletions src/Allegro.DotnetSdk/Sdk/Allegro.NET.Sdk.CSharp.Analyzers.targets

This file was deleted.

11 changes: 1 addition & 10 deletions src/Allegro.DotnetSdk/Sdk/Allegro.NET.Sdk.CSharp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@
<!-- Setup this SDKs defaults -->
<PropertyGroup>
<!-- Enable default analyzers if CPM is not used. -->
<UseAllegroDotnetSdkDefaultAnalyzers Condition="'$(UseAllegroDotnetSdkDefaultAnalyzers)' == '' And '$(ManagePackageVersionsCentrally)' != 'true'">true</UseAllegroDotnetSdkDefaultAnalyzers>
<AllegroDotnetSdkEnableStyleCopConfig Condition="'$(AllegroDotnetSdkEnableStyleCopConfig)' == ''">true</AllegroDotnetSdkEnableStyleCopConfig>
</PropertyGroup>

<PropertyGroup Condition="'$(UseAllegroDotnetSdkDefaultAnalyzers)' == 'true'">
<AllegroDotnetSdkEnableAsyncFixer Condition="'$(AllegroDotnetSdkEnableAsyncFixer)' == ''">true</AllegroDotnetSdkEnableAsyncFixer>
<AllegroDotnetSdkEnableMeziantou Condition="'$(AllegroDotnetSdkEnableMeziantou)' == ''">true</AllegroDotnetSdkEnableMeziantou>
<AllegroDotnetSdkEnableStyleCop Condition="'$(AllegroDotnetSdkEnableStyleCop)' == ''">true</AllegroDotnetSdkEnableStyleCop>
</PropertyGroup>

<!--
Include stylecop configuration if we include StyleCop analyzer within this Sdk,
or if it was included externally as GlobalPackageReference when CPM is enabled.
-->
<ItemGroup Condition="'$(AllegroDotnetSdkEnableStyleCopConfig)' == 'true' And ('$(AllegroDotnetSdkEnableStyleCop)' == 'true' Or @(GlobalPackageReference->WithMetadataValue('Identity','StyleCop.Analyzers')->Count()) > 0)">
<ItemGroup Condition="'$(AllegroDotnetSdkEnableStyleCopConfig)' == 'true' Or @(GlobalPackageReference->WithMetadataValue('Identity','StyleCop.Analyzers')->Count()) > 0)">
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
</ItemGroup>

Expand All @@ -30,6 +23,4 @@
<Using Remove="System.Net.Http" />
</ItemGroup>

<Import Project="Allegro.NET.Sdk.CSharp.Analyzers.targets" />

</Project>
6 changes: 0 additions & 6 deletions src/Allegro.DotnetSdk/Sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
Import our custom targets after Directory.Build.targets is imported
-->
<CustomAfterDirectoryBuildTargets>$(CustomAfterDirectoryBuildTargets);$(MSBuildThisFileDirectory)Allegro.NET.Sdk.targets</CustomAfterDirectoryBuildTargets>

<!--
LEGACY: remove after no more projects reference NetCoreVersions property:
https://sourcegraph.allegrogroup.com/search?q=context:global+repo:AllegroTechies+%22%28NetCoreVersions%29%22&patternType=standard&sm=1&groupBy=repo
-->
<NetCoreVersions>net6.0</NetCoreVersions>
</PropertyGroup>

<Import Project="Allegro.NET.Sdk.props" />
Expand Down

0 comments on commit 0275794

Please sign in to comment.