Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detekt wants different indentation than ktlint #519

Open
kts2 opened this issue Sep 17, 2024 · 1 comment
Open

detekt wants different indentation than ktlint #519

kts2 opened this issue Sep 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@kts2
Copy link

kts2 commented Sep 17, 2024

Expected Behavior

Detekt and ktlint should push for the same indentation.

Observed Behavior

In the attached example detekt wants 12, while ktlint wants 16.
So one of these linters will complain, always.

Steps to Reproduce

  1. Enable File > Settings > Tools > detekt > Rules > Enable formatting (ktlint) rules in AndroidStudio
  2. Write code like
@Composable
fun Example(
    icon: Painter,
    text: String,
    modifier: Modifier = Modifier,
) {
    Row(
        modifier =
        modifier //!!
            .fillMaxWidth() //!!
            .height(50.dp), //!!
        verticalAlignment = Alignment.CenterVertically,
    ) {...}}
  1. The lines marked above with //!! will be reported with bad indentation. If one tool (e.g. ktlint) is allowed to fix the indentation, the other (e.g. detekt) starts complaining and vice versa:

detekt-16to12
ktlint-12to16

Context

I want a warning free code, both from ktlint and detekt.

Your Environment

  • Version of detekt used: detekt plugin (in Android Studio): 2.4.1
  • ktlint plugin (in AS): 0.24.1
  • Version of Gradle used (if applicable): 8.5; Android Gradle plugin: 8.2.2
  • Gradle scan link (add --scan option when running the gradle task): n/a
  • Operating System and version: Ubuntu Linux 22.04
  • Link to your project (if it's a public repository): n/a
@kts2 kts2 added the bug Something isn't working label Sep 17, 2024
@3flex
Copy link
Member

3flex commented Sep 18, 2024

This is likely because the ktlint & detekt IDE plugins you're using are wrapping different versions of ktlint, and the Indentation rule has been updated a few times in ktlint. Those updates can result in conflicting warnings.

There's not much we can do in the core detekt project. I'll move this issue to the detekt-intellij-plugin project.

@3flex 3flex transferred this issue from detekt/detekt Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants