Veggerby.Units.Analyzers
0.2.1
See the version list below for details.
dotnet add package Veggerby.Units.Analyzers --version 0.2.1
NuGet\Install-Package Veggerby.Units.Analyzers -Version 0.2.1
<PackageReference Include="Veggerby.Units.Analyzers" Version="0.2.1" />
<PackageVersion Include="Veggerby.Units.Analyzers" Version="0.2.1" />
<PackageReference Include="Veggerby.Units.Analyzers" />
paket add Veggerby.Units.Analyzers --version 0.2.1
#r "nuget: Veggerby.Units.Analyzers, 0.2.1"
#:package Veggerby.Units.Analyzers@0.2.1
#addin nuget:?package=Veggerby.Units.Analyzers&version=0.2.1
#tool nuget:?package=Veggerby.Units.Analyzers&version=0.2.1
Veggerby.Units.Analyzers
Roslyn analyzers for Veggerby.Units providing early feedback on unsafe or ambiguous unit usage.
These analyzers complement the core library’s deterministic dimensional algebra by surfacing issues directly in the IDE / CI before runtime.
Install
Add the analyzer package alongside the core library. Optionally add the code fixes package for IDE quick actions:
<ItemGroup>
<PackageReference Include="Veggerby.Units" Version="$(VeggerbyUnitsVersion)" />
<PackageReference Include="Veggerby.Units.Analyzers" Version="$(VeggerbyUnitsAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="Veggerby.Units.CodeFixes" Version="$(VeggerbyUnitsCodeFixesVersion)" PrivateAssets="all" />
</ItemGroup>
PrivateAssets="all" keeps analyzers/code fixes from flowing transitively to downstream consumers unless you intend that.
If you only want diagnostics in CI (no IDE code actions) omit the Veggerby.Units.CodeFixes reference.
Rules
| Id | Title | Severity | Description |
|---|---|---|---|
| VUNITS001 | Incompatible unit addition/subtraction | Error | Flags + / - between measurements whose units differ (no implicit conversion performed). |
| VUNITS002 | Ambiguous unit formatting | Info | Warns when calling ToString() / Format() on a measurement whose unit symbol is ambiguous without specifying UnitFormat. |
VUNITS001 – Incompatible unit arithmetic
Disallows adding or subtracting measurements unless their units are structurally identical. Convert explicitly first if needed.
var length = new Int32Measurement(5, Unit.SI.m);
var time = new Int32Measurement(3, Unit.SI.s);
var bad = length + time; // VUNITS001
VUNITS002 – Ambiguous unit formatting
Some symbols (e.g. J, Pa, W, H) map to multiple quantity meanings. Use an explicit UnitFormat (e.g. UnitFormat.Qualified) to clarify output.
var energy = new Int32Measurement(1, Unit.SI.m*Unit.SI.m*Unit.SI.kg/(Unit.SI.s*Unit.SI.s));
var s1 = energy.ToString(); // VUNITS002
var s2 = energy.Format(UnitFormat.Qualified); // OK
Code Fix Support
Install Veggerby.Units.CodeFixes to enable:
- VUNITS001: Adds
.ConvertTo(left.Unit)on the right operand of+/-. - VUNITS002: Appends
UnitFormat.Qualifiedto formatting invocation.
Both fixes support Fix All in Document / Project / Solution.
Suppression
Use standard pragma or GlobalSuppressions.cs when you intentionally violate a rule (rare; prefer fixing instead).
#pragma warning disable VUNITS002
var s = energy.ToString();
#pragma warning restore VUNITS002
Roadmap
- Enrich unit extraction for complex expression flows.
- Direct consumption of shared ambiguity registry (when public hook is finalized).
- Additional rules: affine misuse in arithmetic, redundant unit multiplications, dead dimension factors.
Contributing
- Clone the repo.
- Build & test:
dotnet test(includes analyzer tests). - Add or update rule docs under
docs/analyzers/before submitting PRs.
License
MIT – see repository root LICENSE file.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Veggerby.Units.Analyzers:
| Package | Downloads |
|---|---|
|
Veggerby.Units.CodeFixes
Code fixes for Veggerby.Units analyzers (VUNITS001, VUNITS002). |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.3.0-prerelease0020 | 506 | 12/8/2025 |
| 0.3.0-prerelease0019 | 506 | 12/8/2025 |
| 0.3.0-prerelease0018 | 264 | 11/24/2025 |
| 0.3.0-prerelease0017 | 269 | 11/23/2025 |
| 0.3.0-prerelease0016 | 263 | 11/23/2025 |
| 0.3.0-prerelease0015 | 477 | 11/20/2025 |
| 0.3.0-prerelease0014 | 471 | 11/20/2025 |
| 0.3.0-prerelease0013 | 470 | 11/20/2025 |
| 0.3.0-prerelease0007 | 247 | 9/21/2025 |
| 0.3.0-prerelease0006 | 242 | 9/21/2025 |
| 0.3.0-prerelease0001 | 199 | 9/21/2025 |
| 0.2.1 | 283 | 9/21/2025 |
| 0.2.0 | 301 | 9/19/2025 |
| 0.2.0-prerelease0006 | 314 | 9/19/2025 |
| 0.1.0-prerelease0066 | 151 | 4/12/2026 |
| 0.1.0-prerelease0065 | 163 | 2/18/2026 |
| 0.1.0-prerelease0064 | 163 | 1/13/2026 |
| 0.1.0-prerelease0063 | 166 | 1/13/2026 |
| 0.1.0-prerelease0062 | 162 | 1/6/2026 |
| 0.1.0-prerelease0061 | 520 | 12/9/2025 |
Includes VUNITS001 (unit mismatch in + / -) and VUNITS002 (ambiguous formatting without explicit UnitFormat). See CHANGELOG.md for details.