Giter Club home page Giter Club logo

Comments (10)

3flex avatar 3flex commented on June 3, 2024 1

The Kotlin coding conventions are clear:

If a Kotlin file contains a single class or interface (potentially with related top-level declarations), its name should be the same as the name of the class, with the .kt extension appended. It applies to all types of classes and interfaces.

https://kotlinlang.org/docs/coding-conventions.html#source-file-names

The rule's behaviour aligns. Why not rename the class or the file? If you can't, then you can suppress the rule on this file, or disable the rule in your project.

from detekt.

3flex avatar 3flex commented on June 3, 2024 1

The Compose guidelines also say that the Kotlin coding conventions should be followed (see section "Baseline style guidelines"): https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-api-guidelines.md

You have a few options:

  1. Suppress the rule for the file
  2. Disable the rule for the module
  3. Move the class into its own file

As a general rule we avoid customising rules and behaviour for specific frameworks or libraries though I'll leave this open for a while for others to comment.

from detekt.

atulgpt avatar atulgpt commented on June 3, 2024

I think using

@Composable
fun CustomButton() {
  // 
}

data class CustomButtonData(
  // ...
)

should fix the issue as there is a flag mustBeFirst which is true by default so if you move the function at the top then this rule will not check that file

from detekt.

Abhimanyu14 avatar Abhimanyu14 commented on June 3, 2024

@atulgpt,
I have changed the mustBeFirst to false.
But, it is still not working.

I do not want to reorder the method and classes.

from detekt.

Abhimanyu14 avatar Abhimanyu14 commented on June 3, 2024

The convention aligns only for non-compose code.

For Jetpack Compose code, the Composable method is the main aspect of the file and hence the name will match the Composable name.

from detekt.

Abhimanyu14 avatar Abhimanyu14 commented on June 3, 2024

I would prefer not to suppress or disable the rule as it is very helpful.

I also noticed that the issue is that the functions are not considered at all.

Example,
A file with the name - Test.kt will not throw any error if there is a single top-level function with any other name.

Even rearranging the methods and classes does not help.

File name - CustomButton.kt

@Composable
fun CustomButton() {
  // 
}

data class CustomButtonData(
  // ...
)

is also not compliant.

My proposal is that the top-level methods also have to be included in the checks.

from detekt.

3flex avatar 3flex commented on June 3, 2024

That proposal would be a good one to raise in this third party rule set: https://mrmans0n.github.io/compose-rules/

If it doesn't already exist yet that is.

It's not a good fit for the standard detekt rules though.

from detekt.

Abhimanyu14 avatar Abhimanyu14 commented on June 3, 2024

The above link is not working.
Also, I am not using any third-party rule set.

from detekt.

Abhimanyu14 avatar Abhimanyu14 commented on June 3, 2024

@3flex,
I can see multiple compose rules libraries.
Is there any official one from detekt for the compose rules?

from detekt.

3flex avatar 3flex commented on June 3, 2024

Sorry not sure what happened - the link is fixed now. There's no official detekt rule set for Compose rules but the one I linked to is reasonably popular and should be a good place to start.

from detekt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.