Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.35 KB

File metadata and controls

43 lines (31 loc) · 1.35 KB

SA1018

TypeName SA1018NullableTypeSymbolsMustNotBePrecededBySpace
CheckId SA1018
Category Spacing Rules

Cause

A nullable type symbol within a C# element is not spaced correctly.

Rule description

A violation of this rule occurs when the spacing around a nullable type symbol is not correct.

A nullable type symbol should never be preceded by whitespace, unless the symbol is the first character on the line.

This applies to nullable value types and nullable reference types introduced in C# 8. In a #nullable enable context, code such as string ? value or System.Collections.Generic.List<string?> ? list will trigger this rule. Correct spacing omits the whitespace before the ?, for example string? value or System.Collections.Generic.List<string?>? list.

How to fix violations

To fix a violation of this rule, ensure that there is no whitespace before the nullable type symbol.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1018:NullableTypeSymbolsMustNotBePrecededBySpace", Justification = "Reviewed.")]
#pragma warning disable SA1018 // NullableTypeSymbolsMustNotBePrecededBySpace
#pragma warning restore SA1018 // NullableTypeSymbolsMustNotBePrecededBySpace