ktlint
ktlint copied to clipboard
Unexpected indentation for very long string
Statement
Having a very long string on one line and passing the 100 characters set in Code Style. So since its going like that, I've tried the following cases:
Case 1:
Case 2:
Mentioning that in the Code Style I have Tab size, Indent and Continuation indent at 4.
Expected Behavior
ktlint should pass for both cases
Observed Behavior
Running ktlint it throws the errors for cases case 1: Unexpected indentation (40) (should be 12) case 2: Unexpected indentation (12) (should be 16)
Steps to Reproduce
run ./gradlew ktlint
Your Environment
- Version of ktlint used: 0.39.0
- Android Studio version: 4.1.2
- Kotlin version: 1.4.21-release-Studio4.1-1
- Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task):
- Version of Gradle used (if applicable):
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
com.android.tools.build:gradle:3.6.0
- Operating System and version: macOS Mojave 10.14.6
@Jultom - could you please run with the --verbose
flag to double-check which rule is making this change? we have a couple different rules which can affect line breaks and indentation.
@shashachu let's take Case 1 as the example:
running with verbose, the error will be:
Unexpected indentation (40) (should be 12) (indent)
for each row starting with the second one.
Curious thing... I used ./gradlew ktlintFormat
and it formats the code like this:
After the format, if I run again
./gradlew ktlint
it will pass. But according to my Code Style(rules presented above) it will not fit the rules that I've set.
Also to mention that I use Align when multiline
for expressions.
Yep, the last part (align when multiline setting) isn't supported by the indentation rule yet, hence it cannot accept your 1st case as valid
Current formatting by KtLint is accepted by IntelliJ IDEA default formatting. KtLint will not support align when multiline
unless this becomes part of the Kotlin coding conventions.
Current formatting by KtLint is accepted by IntelliJ IDEA default formatting. KtLint will not support
align when multiline
unless this becomes part of the Kotlin coding conventions.
Closing the issue