squirix.analyzers
0.1.8
dotnet add package squirix.analyzers --version 0.1.8
NuGet\Install-Package squirix.analyzers -Version 0.1.8
<PackageReference Include="squirix.analyzers" Version="0.1.8"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="squirix.analyzers" Version="0.1.8" />
<PackageReference Include="squirix.analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add squirix.analyzers --version 0.1.8
#r "nuget: squirix.analyzers, 0.1.8"
#:package squirix.analyzers@0.1.8
#addin nuget:?package=squirix.analyzers&version=0.1.8
#tool nuget:?package=squirix.analyzers&version=0.1.8
Squirix.Analyzers
Design-time Roslyn analyzers for the squirix ecosystem.
Purpose
Squirix.Analyzers hosts the custom Roslyn diagnostics that enforce squirix's internal coding conventions across its repositories: brace style, member-size limits, naming rules,
and code-smell guards. They are applied at build time and their findings are surfaced as compiler diagnostics (fail the build when TreatWarningsAsErrors is active).
Installation
Add the package reference from nuget.org:
<ItemGroup>
<PackageReference Include="squirix.analyzers" Version="0.1.0"
PrivateAssets="all" OutputItemType="Analyzer"/>
</ItemGroup>
The package ships the analyzer assembly under analyzers/dotnet/cs, so it is loaded as a Roslyn analyzer at build time.
The root .editorconfig carries the severity configuration for the SQR diagnostics. Copy it (or the relevant
dotnet_diagnostic.SQR000x entries) into the consuming repository's .editorconfig.
Some rules read their thresholds from per-rule .editorconfig options. SQR0002 defaults SQR0002.max_methods_per_type
to 20 methods per type, and SQR0003 defaults SQR0003.max_fields_per_type to 15 fields per type. Add the key under a
[*.cs] section in the consuming repository's .editorconfig, e.g.:
[*.cs]
SQR0002.max_methods_per_type = 30
Rules
Rules are prefixed with SQR. Detailed documentation, including non-compliant/compliant examples, lives in
docs/rules. No rule ships an auto-fix (code fix provider) yet.
| Rule | Category | Analyzer | What it enforces |
|---|---|---|---|
SQR0001 |
Style | OmitOuterLoopBracesAnalyzer |
Outer loop body is only a nested loop: drop braces. |
SQR0002 |
Design | TooManyMethodsAnalyzer |
Cap instance/static methods per type (default 20). |
SQR0003 |
Design | TooManyFieldsAnalyzer |
Cap non-literal, non-static-readonly fields (default 15). |
SQR0004 |
Naming | TypeNameTooLongAnalyzer |
Type name at most 40 characters. |
SQR0005 |
Naming | MethodNameTooLongAnalyzer |
Method name at most 40 chars (accessors drop prefix). |
SQR0006 |
Naming | FieldNameTooLongAnalyzer |
Field name at most 40 characters. |
SQR0007 |
Naming | TypeNamespacePrefixAnalyzer |
Type name must not repeat its namespace segment. |
SQR0008 |
Style | RequireMultilineLoopBodyBracesAnalyzer |
Require braces on multi-line loop bodies. |
SQR0009 |
Style | RedundantNamedArgumentAnalyzer |
Prefer positional args; drop names in declaration order. |
SQR0010 |
Style | OmitSingleStatementBracesAnalyzer |
Omit braces for single-line bodies; keep multi-line. |
SQR0011 |
Style | RedundantDefaultArgumentAnalyzer |
Omit arguments equal to the parameter default. |
SQR0012 |
Style | PreferEqualityOperatorAnalyzer |
Prefer ==/!= over is/is-not for null checks. |
SQR0013 |
Style | PreferEqualityOperatorAnalyzer |
Prefer == over is when comparing to a constant. |
SQR0014 |
Style | PreferEqualityOperatorAnalyzer |
Prefer != over is-not when comparing to a constant. |
SQR0015 |
Concurrency | NoBoolDisposedFieldAnalyzer |
Dispose guard must be an int flag via Interlocked. |
SQR0016 |
Concurrency | NoBoolDisposedFieldAnalyzer |
int dispose flag only via Interlocked/Volatile. |
SQR0017 |
Usage | NoDirectTestContextCancelTokenAnalyzer |
Don't use TestContext.Current.CancellationToken directly. |
SQR0018 |
Style | RequireMultilineIfBodyBracesAnalyzer |
Require braces on multi-line if/else bodies. |
SQR0019 |
Usage | NoAllocatingThrowsAssertAnalyzer |
Avoid allocating exception assert invocations. |
SQR0020 |
Usage | MergeDuplicateCatchBlocksAnalyzer |
Merge consecutive catch blocks with identical bodies. |
SQR0021 |
Usage | UseArgumentExceptionThrowHelperAnalyzer |
Prefer ArgumentException.ThrowIf* over manual guards. |
SQR0022 |
Usage | UseTimeSpanThrowHelperAnalyzer |
Prefer ArgumentOutOfRangeException.ThrowIf* for TimeSpan guards. |
SQR0023 |
Usage | CoalesceThrowIfNullAnalyzer |
Prefer ArgumentNullException.ThrowIfNull over null-coalescing throw. |
SQR0024 |
Usage | CoalesceThrowHelperAnalyzer |
Prefer a throw-helper method over null-coalescing throw. |
Building
Requires the .NET SDK. The analyzer target is netstandard2.1; the unit-test project targets net10.0.
dotnet build Squirix.Analyzers.slnx -c Release
dotnet test tests/squirix.analyzers.unit-tests/Squirix.Analyzers.UnitTests.csproj -c Release
dotnet pack src/squirix.analyzers/squirix.analyzers.csproj -c Release -o ./artifacts
The packed analyzer is emitted under artifacts/squirix.analyzers.<version>.nupkg.
License
Licensed under the Apache License, Version 2.0.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.