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

Remediation

Move the to column one. Where the nesting of the directives themselves needs to be shown, indent after the instead - # if and # endif are valid and keep the marker aligned at the left margin.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved