Skip to content

Allow enabling custom rulesets for ktlint #1220

Description

@jonesetc

Follow up from #409 (comment)

I had been watching the issue around this before, but it was closed after just the first request (experimental ruleset) was completed. Currently my team runs a second formatting plugin (https://github.com/JLLeitschuh/ktlint-gradle) that reruns ktlint so that we can use a custom ruleset that helps us avoid some common pitfalls in our codebase.

The way that we use this today looks roughly like:

build.gradle.kts

plugins {
    java
    kotlin("jvm")
    id("com.diffplug.spotless")
    // The extra ktlint plugin
    id("org.jlleitschuh.gradle.ktlint")
}

dependencies {
    // Add the ruleset from a submodule
    ktlintRuleset(project(":linting"))
}

spotless {
    kotlin {
        target("**/*.kt")
        ktlint()
    }
}

// After running spotlessApply or spotlessCheck, run a last check with the custom rules
tasks.spotlessKotlin {
    finalizedBy(
        "ktlintCheck"
    )
}

Activity

  1. bengaudiosi-toast commented on Aug 30, 2023

    @bengaudiosi-toast

    Any movement on this?

  2. Goooler commented on Nov 21, 2023

    @Goooler
    Member

    Addressing the fix to #1896.

  3. nedtwigg commented on Nov 27, 2023

    @nedtwigg
    Member

    Implemented in plugin-gradle 6.23.0 and plugin-maven 2.41.0 thanks to the incredibly prolific @Goooler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions