lint/strict/dotnet
Nullable, recommended analyzers and warnings as errors are on
Implements lint/strict for dotnet.
| Severity | warning |
| Tiers | 1, 2 |
| Stacks | dotnet |
| Scope | each |
| Kind | expr |
| Source | library v0.1.0 |
| Selected by | fleetlint-recommended@v0.1.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)).
See: https://fleetlint.org/baseline/#static-analysis, https://fleetlint.org/stacks/#net
Generated by fleetlint docs from catalog v0.1.0.