Skip to content

statement-indent

all languagesstylefix: safedefault: offcmake/cmake-lint

Reports a statement, the closing parenthesis of a multi-line statement or a comment between statements that is not at the column that its block depth gives (depth times size, default 2) in a language whose files are a flat list of commands with block words such as if and endif (CMake). With allow_unindented a token in column 0 is accepted at any depth. A comment between statements may sit at the depth of the statement before or after it. The fix rewrites the white space before the token.

In a flat list of commands the indentation is the only sign of the blocks, because nothing but the block words delimit them. When it is wrong the reader sees a different nesting than the one that runs.

To fix, indent to the block depth; the fix does it.

Reported
if(A)
set(x 1)
# fine: the depth of the body
else()
foreach(i a b)
...
After the fix
if(A)
set(x 1)
# fine: the depth of the body
else()
foreach(i a b)
...
lint:
rules:
statement-indent:
level: warn # off (default), warn, error
options:
size: 2
allow_unindented: false
Option Type Default Description
size int 2 Columns per block depth.
allow_unindented bool false Accept a token at column 0 whatever its depth.

Enabled by the presets: cmake/cmake-lint.

Suppress one line with sudsy-disable-next-line statement-indent in a comment of the file’s language.

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

Tool Rule Match
cmake-lint C0307 full