https://kotlinlang.org logo
#ktlint
Title
# ktlint
u

Ubed

03/04/2024, 12:49 PM
Hey, I'm new to ktlint and i want to define some custom rules in my micronaut kotlin project for formatting. How can i achieve it? Any suggestion or guide would be helpful. Thanks.
p

Paul Dingemans

03/04/2024, 1:25 PM
u

Ubed

03/05/2024, 7:23 AM
thanks @Paul Dingemans I'm just concerned about ignoring standard function name and added this in my build.gradle
Copy code
ktlint {
    android = false
    outputToConsole = true
    disabledRules = [
        "final-newline",
        "standard:function-naming"
    ]
}
but it's still raising error -
Function name should start with a lowercase letter (except factory methods) and use camel case (cannot be auto-corrected)
p

Paul Dingemans

03/05/2024, 8:08 AM
It loos that you are using a wrapper/plugin around ktlint. Please consult their documentation how to disable rules of ktlint.
u

Ubed

03/05/2024, 8:09 AM
Yes @Paul Dingemans i'm using this plugin
id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
adding this on the top of the file worked for me in ignoring that file
@file:Suppress("ktlint")
@Paul Dingemans WDYT is it a recommended approach or we should avoid it?
p

Paul Dingemans

03/05/2024, 8:17 AM
You should only use that if you want to apply that for a single file. But you do not want to add that to every file. Best way to disable is to use '.editorconfig'.
w

wakingrufus

03/05/2024, 11:50 PM
Yes, the disabled rules property of ktlint-gradle is deprecated and doesnt work with newer ktlint versions (since 0.48) use editorconfig instead
12 Views