(#) Suspicious indentation
!!! ERROR: Suspicious indentation
This is an error.
Id
: `SuspiciousIndentation`
Alias
: SuspiciousIndentAfterControlStatement
Summary
: Suspicious indentation
Severity
: Error
Category
: Correctness
Platform
: Any
Vendor
: Android Open Source Project
Feedback
: https://issuetracker.google.com/issues/new?component=192708
Affects
: Kotlin and Java files
Editing
: This check runs on the fly in the IDE editor
Implementation
: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/IndentationDetector.kt)
Tests
: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/IndentationDetectorTest.kt)
Copyright Year
: 2021
This check looks for cases where the indentation suggests a grouping
that isn't actually there in the code. A common example of this would be
something like
```kotlin
if (column > width)
line++
column = 0
```
Here, the `column = 0` line will be executed every single time, not just
if the condition is true.
(##) Options
You can configure this lint checks using the following options:
(###) always-run
Whether this check should be included while editing.
While you're editing, it's common to have a temporary situation where you have suspicious indentation scenarios -- e.g. you start typing an `if` statement on the line above something you want to make conditional, and you haven't indented it yet. It can be distracting and misleading to suddenly have both statements light up as errors. Therefore, lint will avoid including this check when running on the fly in the editor, unless it looks like the file has not been recently edited. With this option, you can turn it on in all cases.
Default is false.
Example `lint.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
<lint>
<issue id="SuspiciousIndentation">
<option name="always-run" value="false" />
</issue>
</lint>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(##) Example
Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
src/Kotlin.kt:8:Error: Suspicious indentation: This is indented but is
not nested under the previous expression (if (this[i] == '\n')...)
[SuspiciousIndentation]
line++ // WARN1
------
src/Kotlin.kt:15:Error: Suspicious indentation: This is indented but is
not continuing the previous expression (var s = "The price i...)
[SuspiciousIndentation]
price.toString() + // WARN 2
----------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here is the source file referenced above:
`src/Kotlin.kt`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers
fun String.getLineAndColumn(offset: Int): Pair