Style rules
Small consistency rules and pragma hygiene.
Rules
| Rule | Title | Code fix |
|---|---|---|
| E128002 | Use string.Empty instead of "" | Yes |
| E128006 | Use Encoding.UTF8 instead of Encoding.Default | Yes |
| E128024 | Non-XML-doc comment above method declaration | Yes |
| E128025 | Use Path.GetRandomFileName() instead of Guid.NewGuid() in temp paths | Yes |
| E128043 | Do not use the null-forgiving operator | Yes |
| E128047 | #pragma warning disable without justification comment | Yes |
| E128055 | Unbalanced #pragma warning disable without matching restore | Yes |
| E128063 | Mid-name underscore in private static member (IDE1006 rename artifact) (default: Error, silent in test code) | Yes |
| E128065 | #pragma warning disable with multiple IDs — use one pragma per ID | Yes |
| E128094 | #pragma warning disable before file-scoped namespace (default: Error) | Yes |
Rule details
E128002: string.Empty
Flags empty string literals (""). string.Empty is clearer and avoids allocation ambiguity.
E128006: Encoding.UTF8
Flags Encoding.Default and Encoding.ASCII. Encoding.Default is platform-specific; Encoding.ASCII silently drops non-ASCII characters. Use Encoding.UTF8.
E128024: Non-XML-doc comment above method
Flags // comments immediately preceding method or local function declarations. Use /// <summary> XML doc comments for documentation, or remove the comment entirely.
// Before (warns)
// Does the thing
void DoThing() { }
// After (option 1: XML doc)
/// <summary>Does the thing.</summary>
void DoThing() { }
// After (option 2: remove)
void DoThing() { }
The analyzer is NonXmlDocCommentE128Analyzer in Style/NonXmlDocCommentE128Analyzer.cs. It skips a member whose leading trivia holds a #pragma warning disable directive (a restore does not skip), because the comment explains the suppression. The old review notes call this analyzer XmlDocCommentAnalyzer, which does not exist.
E128025: Guid.NewGuid() in temp paths
Flags Guid.NewGuid() inside string interpolation within Path.Combine or Path.GetTempPath calls. Use Path.GetRandomFileName() instead.
// Before (warns)
var path = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.tmp");
// After
var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
E128043: Null-forgiving operator
Flags every use of the null-forgiving operator (!). The operator suppresses nullable analysis without ensuring the value is non-null, hiding potential NullReferenceExceptions.
E128047: Suppression without justification
Flags #pragma warning disable directives that don’t have an accompanying justification comment on the same or preceding line. Every suppression should explain why.
E128055: Unbalanced pragma warning disable
Flags #pragma warning disable directives that are never matched by a corresponding #pragma warning restore in the same file. An unbalanced disable suppresses diagnostics for the rest of the file, silently hiding real issues.
// Before (warns — no restore)
#pragma warning disable CS8600
// After
#pragma warning disable CS8600
string? value = GetValue();
#pragma warning restore CS8600
E128063: Mid-name underscore in private static member
Flags private/internal static members whose name contains an underscore at index ≥ 2 (e.g., Nots_supportedExtensions, Creates_enrichmentJsonOptions, Spectres_terminal). These are artifacts of IDE1006 batch-rename operations that mangle identifiers by inserting underscores at word boundaries instead of adjusting capitalization. Excludes: leading underscore (_foo), Hungarian prefix (s_foo, m_foo, t_foo), const fields, op_ operator methods, __ double-underscore patterns, and compiler-generated property accessors. The rule is silent in a test compilation, where test names and static test helpers use underscores by convention.
// Before (warns)
private static readonly string[] Nots_supportedExtensions = [];
// After
private static readonly string[] NotsSupportedExtensions = [];
E128065: Bundled pragma warning disable
Flags #pragma warning disable directives that list more than one diagnostic ID. Each suppression requires independent justification; bundling multiple IDs on one line hides weak reasoning and makes suppression audits harder. Split into one pragma per ID so each can carry its own justification comment. Companion to E128055.
// Before (warns)
#pragma warning disable CS8600, CS8602
// After
#pragma warning disable CS8600
#pragma warning disable CS8602
E128094: Pragma warning disable placed before a file-scoped namespace declaration
Flags a #pragma warning disable that sits above namespace X;. The directive sits outside the namespace it was meant to scope. IDE0079 treats it as unnecessary and removes it during format, so the suppression stops working. The rule reports at error.
// Before (error)
#pragma warning disable CS1591
namespace App;
// After
namespace App;
#pragma warning disable CS1591