Skip to content

directive-keyword-space

C#stylefix: safedefault: offcsharp/stylecop

Reports a preprocessor directive that has a space between # and its keyword (# if). The fix removes the space.

The convention writes the directive as one word, #if, #region, so a search for it finds all of them and the directives look alike.

Reported
class A {
# region R
int a;
# endregion
# if X
int b;
#endif
}
After the fix
class A {
#region R
int a;
#endregion
#if X
int b;
#endif
}
csharp:
lint:
rules:
directive-keyword-space: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line directive-keyword-space in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1006 full