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

Feature/remove analyzers references #19

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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>
rafalschmidt97 marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

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

## Analyzers
rafalschmidt97 marked this conversation as resolved.
Show resolved Hide resolved

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>
rafalschmidt97 marked this conversation as resolved.
Show resolved Hide resolved
<PackageVersion>2.2.0</PackageVersion>
rafalschmidt97 marked this conversation as resolved.
Show resolved Hide resolved
<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)">
rafalschmidt97 marked this conversation as resolved.
Show resolved Hide resolved
<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>
rafalschmidt97 marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

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