pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.21k stars 510 forks source link

Unexpected indentation (expected 8, actual 12) #558

Closed mnewlive closed 4 years ago

mnewlive commented 5 years ago

Have next code:

interface BiometricPromptAbs {

    var resultCallback: BiometricPromptCallback?
    fun showBiometricPrompt(
            context: FragmentActivity,
            @StringRes titleResId: ResId,
            @StringRes descriptionResId: ResId,
            @StringRes negativeActionTextResId: ResId
    )
}

Specifies the same error for all four parameters:

Unexpected indentation (expected 8, actual 12)

I tried to configure the project as shown here and here But the error remained.

Some code from my root build.gradle:

buildscript {
    ext.kotlin_version = '1.3.41'
    repositories {
        jcenter()
        google()
        mavenLocal()
        maven { url 'https://maven.fabric.io/public' }
        gradlePluginPortal()
    }
dependencies { 
        classpath "org.jlleitschuh.gradle:ktlint-gradle:8.2.0"
    }

subprojects {
    apply plugin: "org.jlleitschuh.gradle.ktlint" // Version should be inherited from parent

    // Optionally configure plugin
    ktlint {
        debug = true
    }

    dependencies {
        ktlintRuleset project(':ktlint_rules')
    }
}
mnewlive commented 5 years ago

codeStyle

Use this settings, and use 4 in field Continuation indent:

codeStyle2 Everything seems to work, but I'm sure it will be right :thinking: :wink:

imGurpreetSK commented 5 years ago

Also, if the indentation of a line is more than the required one, but in multiples of the set indentation value, ktlint fails to report an error.

Example: An error will be reported in this case:

override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState) // 10 spaces indent
        setContentView(R.layout.main_activity)
}

but not in this case:

override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState) // 12 spaces indent, should be 8 ideally.
        setContentView(R.layout.main_activity)
}
lxdraw commented 4 years ago

I am seeing the same issue as @GurpreetSK95. When a continuation indent is any multiple of the indent size it passes validation.

fun findById(id: String): Mono<Thing> =
        databaseClient
                                    .execute(SqlStatements.findById)
            .bind("id", id)
            .map(Thing::map)
            .first()

I think this should count as a violation.

christianhujer commented 4 years ago

To me, this is a bug in ktlint. IntelliJ IDEA Ultimate Edition default settings should be regarded as correct, they are "from the creators".

romtsn commented 4 years ago

@lxdraw @imGurpreetSK this should be fixed already - please use the latest version. @mnewlive let's track this in #805 - I've filed an issue on JB's side, hopefully we'll get some guidance

Pirokar commented 1 year ago

image The same bug