TypeName | SA1028CodeMustNotContainTrailingWhitespace |
CheckId | SA1028 |
Category | Spacing Rules |
📝 This rule is new for StyleCop Analyzers, and was not present in StyleCop Classic.
A line of code ends with a space, tab, or other whitespace characters before the end of line character(s).
A violation of this rule occurs when a line of code ends with any form of whitespace other than the end of line character(s). Extra whitespace can show up in editors with visible whitespace, or cause unnecessary code churn when developers format the document such that trailing whitespace is removed later. Some diff tools even highlight trailing whitespace to encourage developers to trim it.
The C# language contains several constructs which span multiple lines of code. The following table describes the behavior of this rule with respect to each of these constructs.
Construct | Analysis Enabled |
---|---|
"Normal" code | ✔ |
Line comments (starting with // ... ) |
✔ |
Inside block comments (/* ... */ ) |
✔ |
Single-line documentation comments (/// ... ) |
✔ |
Multi-line documentation comments (/** ... */ ) |
✔ |
Preprocessor directives (#if , #pragma , #region , etc.) |
✔ |
Verbatim string literals (@"" ) |
|
Disabled code (text located within a #if , #elif , or #else block which is not active) |
The fix an instance of this violation, delete all excess whitespace characters at the end of the line.
#pragma warning disable SA1028 // Code should not contain trailing whitespace
SomeMethodWithSpaceAfterTheSemicolon();
#pragma warning restore SA1028 // Code should not contain trailing whitespace