Veggerby.Units.Analyzers 0.3.0-prerelease0007

This is a prerelease version of Veggerby.Units.Analyzers.
dotnet add package Veggerby.Units.Analyzers --version 0.3.0-prerelease0007
                    
NuGet\Install-Package Veggerby.Units.Analyzers -Version 0.3.0-prerelease0007
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Veggerby.Units.Analyzers" Version="0.3.0-prerelease0007" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Veggerby.Units.Analyzers" Version="0.3.0-prerelease0007" />
                    
Directory.Packages.props
<PackageReference Include="Veggerby.Units.Analyzers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Veggerby.Units.Analyzers --version 0.3.0-prerelease0007
                    
#r "nuget: Veggerby.Units.Analyzers, 0.3.0-prerelease0007"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Veggerby.Units.Analyzers@0.3.0-prerelease0007
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Veggerby.Units.Analyzers&version=0.3.0-prerelease0007&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Veggerby.Units.Analyzers&version=0.3.0-prerelease0007&prerelease
                    
Install as a Cake Tool

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.Qualified to 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

  1. Clone the repo.
  2. Build & test: dotnet test (includes analyzer tests).
  3. Add or update rule docs under docs/analyzers/ before submitting PRs.

License

MIT – see repository root LICENSE file.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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-prerelease0007 162 9/21/2025
0.3.0-prerelease0006 158 9/21/2025
0.3.0-prerelease0001 132 9/21/2025
0.2.1 160 9/21/2025
0.2.0 234 9/19/2025
0.2.0-prerelease0006 243 9/19/2025

Includes VUNITS001 (unit mismatch in + / -) and VUNITS002 (ambiguous formatting without explicit UnitFormat). See CHANGELOG.md for details.