mrmans0n / compose-rules

Lint rules for ktlint/detekt aimed to contribute to a healthier usage of Compose. Actively maintained and evolved fork of the Twitter Compose rules.
https://mrmans0n.github.io/compose-rules
Other
550 stars 21 forks source link

while using compose rules standard:function-naming #315

Closed azmiradi97 closed 1 month ago

azmiradi97 commented 1 month ago
// Lists all plugins used throughout the project
allprojects {
    apply(plugin = "org.jlleitschuh.gradle.ktlint")

    dependencies {
        // Use version 0.3.21 as later versions support Kotlin 2,
        // which is not compatible with the current project's Kotlin version.
        ktlintRuleset("io.nlopez.compose.rules:ktlint:0.3.21")
    }

    // Configure ktlint settings
    ktlint {
        debug.set(true) // Enables debug logging
        verbose.set(true) // Enables verbose output
        android.set(true) // Enables Android-specific rules
        outputToConsole.set(true) // Outputs results to the console
        outputColorName.set("RED") // Sets the output color to red
        ignoreFailures.set(false) // Fails the build if there are any lint errors

        // Configure ktlint reporters
        reporters {
            reporter(ReporterType.CHECKSTYLE) // Generates a Checkstyle report
            reporter(ReporterType.HTML) // Generates an HTML report
        }

        // Configure file filter for ktlint
        filter {
            exclude("**/generated/**") // Excludes generated files from linting
            include("**/kotlin/**") // Includes only Kotlin files for linting
        }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="8.0">
    <file name="/......./TestKtlint.kt">
        <error line="10" column="5" severity="error" message="Function name should start with a lowercase letter (except factory methods) and use camel case" source="standard:function-naming" />
    </file>
</checkstyle>

import androidx.compose.runtime.Composable

class TestKtlint {
    fun test1() {}
}

@Composable
fun DDDDDD() {}

@Composable
fun fDD(): Float {
    return 0f
}

why produce this error Function name should start with a lowercase letter (except factory methods) and use camel case" source="standard:function-naming

mrmans0n commented 1 month ago

That error is from the ktlint standard ruleset, not this ruleset.

ktlint documentation about that particular rule can be found here: https://pinterest.github.io/ktlint/latest/rules/standard/#function-naming

They have a section in there that talks about how to configure it for compose:

When using Compose, you might want to configure the function-naming rule with .editorconfig property ktlint_function_naming_ignore_when_annotated_with=Composable. Furthermore, you can use a dedicated ktlint ruleset like Compose Rules for checking naming conventions for Composable functions.

Follow their documentation and it should work.

azmiradi97 commented 1 month ago

But report mention to compose fun

@Composable fun DDDDDD() {}

mrmans0n commented 1 month ago

source="standard:function-naming" means standard ruleset, so ktlint. It's telling you that the function name is invalid, because you haven't configured ktlint for compose as I linked above.

azmiradi97 commented 1 month ago

okay thank you i understand you @mrmans0n