Preprocessor directive is indented
ID |
objectivec.maintainability.indented_preprocessor_directive |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Preprocessor |
Language |
Objective-C |
Description
Reports a conditional-compilation, definition or inclusion directive whose # is not in the first column. #pragma is not reported, because compiler pragmas such as #pragma clang diagnostic push are conventionally indented with the code they wrap.
Rationale
The preprocessor runs before the compiler and its nesting is unrelated to the brace nesting of the code around it, so an indented #if reads as if it belonged to the enclosing block when it does not. Keeping every directive in column one makes the conditional-compilation structure of a file scannable down the left margin, and stops a directive from being hidden inside a deeply indented function body where a reader looking for the conditions that select a build will not see it.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Preprocessor directive is indented
#define kLogLevel 4