1.. title:: clang-tidy - readability-misleading-indentation 2 3readability-misleading-indentation 4================================== 5 6Correct indentation helps to understand code. Mismatch of the syntactical 7structure and the indentation of the code may hide serious problems. 8Missing braces can also make it significantly harder to read the code, 9therefore it is important to use braces. 10 11The way to avoid dangling else is to always check that an ``else`` belongs 12to the ``if`` that begins in the same column. 13 14You can omit braces when your inner part of e.g. an ``if`` statement has only 15one statement in it. Although in that case you should begin the next statement 16in the same column with the ``if``. 17 18Examples: 19 20.. code-block:: c++ 21 22 // Dangling else: 23 if (cond1) 24 if (cond2) 25 foo1(); 26 else 27 foo2(); // Wrong indentation: else belongs to if(cond2) statement. 28 29 // Missing braces: 30 if (cond1) 31 foo1(); 32 foo2(); // Not guarded by if(cond1). 33 34Limitations 35----------- 36 37Note that this check only works as expected when the tabs or spaces are used 38consistently and not mixed. 39