Analysis for Intellenum
Analyzer Rules
This outlines the rules used by the Intellenum analyzers, including shipped and unshipped releases.
Shipped Analyzer Rules
src/Intellenum/AnalyzerReleases.Shipped.md
Rule ID | Category | Severity | Notes |
---|---|---|---|
INTELLENUM010 | Usage | Error | DoNotUseNewAnalyzer |
INTELLENUM009 | Usage | Error | DoNotUseDefaultAnalyzer |
INTELLENUM025 | Usage | Error | DoNotUseReflection |
Unshipped Analyzer Rules
src/Intellenum/AnalyzerReleases.Unshipped.md
Rule ID | Category | Severity | Notes |
---|---|---|---|
INTELLENUM030 | Usage | Error | DuplicateMembersAnalyzer |
Analyzer Tests
The Intellenum analyzers are tested in the tests/AnalyzerTests
project.
tests/AnalyzerTests/AnalyzerTests.csproj
<ItemGroup>
<ProjectReference Include="..\src\Intellenum\Intellenum.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<CodeAnalysisRuleSet>..\src\Intellenum\Intellenum.ruleset</CodeAnalysisRuleSet>
<AnalysisMode>All</AnalysisMode>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
</PropertyGroup>
<ItemGroup>
<Compile Include="DoNotUseDefaultAnalyzerTests.cs" />
<Compile Include="DoNotUseNewAnalyzerTests.cs" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="obj\Debug\net8.0\AnalyzerTests.AssemblyInfoInputs.cache" />
</ItemGroup>
This shows that the tests:
- Reference the Intellenum project.
- Use the
Microsoft.CodeAnalysis.Analyzers
package. - Run with the
net8.0
framework.
Test Execution
The test.ps1
script is used to run the end-to-end tests for the Intellenum analyzers.
# Run the end to end tests. The tests can't have project references to Intellenum. This is because, in Visual Studio,
# it causes conflicts caused by the difference in runtime; VS uses netstandard2.0 to load and run the analyzers, but the
# test project uses a variety of runtimes. So, it uses NuGet to reference the Intellenum analyzer. To do this, this script first
# builds and packs Intellenum using a ridiculously high version number and then restores the tests NuGet dependencies to use that
# package. This will allow you run and debug debug these tests in VS, but to use any new code changes in the analyzer, you
# need to rerun this script to force a refresh of the package.
$artifacts = ".\artifacts"
$localPackages = ".\local-global-packages"
This script builds and packs the Intellenum analyzer with a high version number, then uses NuGet to restore dependencies in the test project.
Test Examples
Here are examples of how the Intellenum analyzers are tested:
tests/AnalyzerTests/DoNotUseNewAnalyzerTests.cs
using Xunit;
namespace AnalyzerTests
{
public class DoNotUseNewAnalyzerTests
{
[Fact]
public async Task Test_DoNotUseNewAnalyzer_New_Instance()
{
// Code for testing the DoNotUseNewAnalyzer rule
}
[Fact]
public async Task Test_DoNotUseNewAnalyzer_New_Instance_With_Attribute()
{
// Code for testing the DoNotUseNewAnalyzer rule with attributes
}
}
}
tests/AnalyzerTests/DoNotUseDefaultAnalyzerTests.cs
using Xunit;
namespace AnalyzerTests
{
public class DoNotUseDefaultAnalyzerTests
{
[Fact]
public async Task Test_DoNotUseDefaultAnalyzer_Default_Instance()
{
// Code for testing the DoNotUseDefaultAnalyzer rule
}
}
}
These examples show how the DoNotUseNewAnalyzer
and DoNotUseDefaultAnalyzer
rules are tested using the [Fact]
attribute and Task
methods.
Top-Level Directory Explanations
samples/ - This directory contains example projects demonstrating the usage of Intellenum.
samples/Intellenum.Examples/ - Contains various example projects demonstrating different aspects of Intellenum, such as serialization, conversion, syntax examples, types, typical scenarios, and more.
samples/WebApplication/ - Contains a sample web application that uses Intellenum.
src/ - This directory contains the source code of the Intellenum library.
src/Benchmarks/ - Contains benchmark tests for the Intellenum library.
src/Intellenum.CodeFixers/ - Contains code fixers for the Intellenum library.
src/Intellenum/ - Contains the main source code for the Intellenum library. This directory is further divided into subdirectories for diagnostics, extensions, generators, member building, properties, rules, static constructor building, templates, and more.
tests/ - This directory contains test projects for the Intellenum library.
tests/AnalyzerTests/ - Contains unit tests for the Intellenum analyzer.
tests/ConsumerTests/ - Contains tests for consuming the Intellenum library.
tests/Intellenum.Tests/ - Contains additional tests for the Intellenum library.
tests/Shared/ - Contains shared test files.
tests/SnapshotTests/ - Contains snapshot tests for the Intellenum library.
tests/Testbench/ - Contains a test bench for the Intellenum library.