ktlint icon indicating copy to clipboard operation
ktlint copied to clipboard

Unexpected indentation for very long string

Open Jultom opened this issue 4 years ago • 3 comments

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: Screenshot 2021-01-27 at 17 56 42

Case 2: Screenshot 2021-01-27 at 17 56 59

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 avatar Jan 27 '21 16:01 Jultom

@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 avatar Feb 09 '21 17:02 shashachu

@shashachu let's take Case 1 as the example: Screenshot 2021-02-10 at 13 40 21 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: Screenshot 2021-02-10 at 13 41 09 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.

Jultom avatar Feb 10 '21 11:02 Jultom

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

romtsn avatar Mar 08 '21 07:03 romtsn

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.

paul-dingemans avatar Nov 02 '22 15:11 paul-dingemans

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

paul-dingemans avatar Nov 23 '22 17:11 paul-dingemans