fleetlint Policy for a fleet of repositories
v0.7
Getting started

lint/strict/dotnet

Nullable, recommended analyzers and warnings as errors are on

Implements lint/strict for dotnet.

Severitywarning
Tiers1, 2
Stacksdotnet
Scopeeach
Kindexpr
Sourcelibrary v0.4.0
Selected byfleetlint-recommended@v0.4.0

Requirement

Directory.Build.props (or every project file) sets <Nullable>enable, <TreatWarningsAsErrors>true and <AnalysisLevel>latest-recommended or latest-all (a version number or <AnalysisMode>Recommended/All also counts; for the analysis level, dotnet_analyzer_diagnostic.severity = warning or error in .editorconfig counts too).

Why

Analyzers at their default level report little, and warnings that do not fail the build are ignored; latest-minimum or latest-none keep the switch but not the checks.

Applies when

["", "../", "../../", "../../../"].exists(d, file(d + "Directory.Build.props")
  || (file(d + ".editorconfig") && text(d + ".editorconfig").contains("dotnet_analyzer_diagnostic")))
|| (glob("**/*.csproj") + glob("**/*.fsproj")).exists(p, text(p).matches("<(Nullable|TreatWarningsAsErrors|AnalysisLevel|AnalysisMode)>"))

Check

For each item in:

params.required
[item == "Nullable" ? "<Nullable>\\s*enable\\s*<"
  : (item == "TreatWarningsAsErrors" ? "<TreatWarningsAsErrors>\\s*true\\s*<"
  : (item == "AnalysisLevel" ? "<AnalysisLevel>\\s*(latest|preview|\\d+(\\.\\d+)?)-(recommended|all)\\s*<|<AnalysisMode>\\s*(Recommended|All)\\s*<"
  : "<" + item + ">\\s*true\\s*<"))]
.exists(re,
  ["", "../", "../../", "../../../"].exists(d, file(d + "Directory.Build.props") && text(d + "Directory.Build.props").matches(re))
  || [glob("**/*.csproj") + glob("**/*.fsproj")].exists(ps, ps.size() > 0 && ps.all(p, text(p).matches(re)))
  || (item == "AnalysisLevel" && ["", "../", "../../", "../../../"].exists(d, file(d + ".editorconfig")
    && text(d + ".editorconfig").matches("(?m)^\\s*dotnet_analyzer_diagnostic\\.severity\\s*=\\s*(warning|error)\\b"))))

Parameters

  • required: [Nullable TreatWarningsAsErrors AnalysisLevel]

Fix

Set the reported properties in Directory.Build.props (fleetlint fix --apply writes the file when it is missing).

Agent instruction: Set each reported property in Directory.Build.props and fix the warnings that become errors instead of lowering the level.

fleetlint fix can apply this rule’s fix automatically (1 action(s)).

Sources


Generated by fleetlint docs from catalog v0.4.0.