Skip to content

Lint for misleading indentation #10483

Closed
Closed
@glaebhoerl

Description

@glaebhoerl

While working in C++, I was recently bitten by having accidentally omitted the closing brace of one if-else statement among many others. The compiler only complained of a syntax error many lines lower down at the beginning of the next function, and it took me a while to find where the problem was, because visually, I normally interpret code by looking at indentation, which matched my intent. On the other hand, the compiler ignores indentation and looks only at braces, which did not match my intent. In this case I got a compile error, but in other cases bad indentation can cause a human to derive a different meaning when reading (syntactically well-formed) code than the compiler does, leading to bugs.

This is the drawback of whitespace-irrelevant syntax: the programmer has to encode the same information in two separate ways, introducing more opportunities to make mistakes. We could have a lint which complains if the "logical" and visual indentations of code don't align to help catch these kind of problems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions