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

Indent + parameter wrapping rules cause " Format was not able to resolve all violations" warning with long lines #2488

Closed
vinaygopinath opened this issue Jan 4, 2024 · 3 comments · Fixed by #2491
Milestone

Comments

@vinaygopinath
Copy link

vinaygopinath commented Jan 4, 2024

When the parameter-wrapping and indent rules are enabled, and a function parameter exceeds the max line length, ktlint -F shows the warning

KtLintRuleEngine -- Format was not able to resolve all violations which (theoretically) can be autocorrected in file <absolute file path> in 3 consecutive runs of format

Sample code

class MyClass @Inject constructor(
  val someReallyLongFieldNameUsedInMyClass: SomeReallyLongDependencyClass
)

Expected Behavior

I believe the expected formatted output is

class MyClass @Inject constructor(
  val someReallyLongFieldNameUsedInMyClass:
    SomeReallyLongDependencyClass
)

Observed Behavior

The actual formatted output is

class MyClass @Inject constructor(
  val someReallyLongFieldNameUsedInMyClass:
  SomeReallyLongDependencyClass // I wonder if the class name *not* being indented is the cause of the issue?
)

Your Environment

  • Version of ktlint used: 1.1.0
  • Relevant parts of the .editorconfig settings
    [*]
    charset = utf-8
    end_of_line = lf
    max_line_length = 100
    
    [*.{kt,kts}]
    ktlint_code_style = android_studio
    
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): Command line
  • Operating System and version: Debian Testing, 6.1.0-15-amd64 Gradle build error #1 SMP PREEMPT_DYNAMIC Debian 6.1.66-1 (2023-12-09) x86_64 GNU/Linux
@vinaygopinath
Copy link
Author

vinaygopinath commented Jan 4, 2024

On second thought, I think the warning is due to the interaction between

  1. standard:parameter-list-spacing which expects the field name and its class to be separated by a colon and a space, as in exactly in the unformatted code
    class MyClass @Inject constructor(
      val someReallyLongFieldNameUsedInMyClass: SomeReallyLongDependencyClass
    )
  2. standard:parameter-wrapping which, when the field name and class name exceed the max line length, complains about a "Missing newline before SomeReallyLongDependencyClass"
  3. standard:max-line-length
  4. and standard:indent

@paul-dingemans
Copy link
Collaborator

Technically I could not reproduce your problem because you most likely have changed the class names to shorter names. But with decreasing the max_line_length to 74, I was able to reproduce it.

@paul-dingemans paul-dingemans added this to the 1.1.1 milestone Jan 4, 2024
@paul-dingemans
Copy link
Collaborator

Problem is indeed caused by rules parameter-list-spacing and parameter-wrapping. They disagree with each other about how to format the parameter.

paul-dingemans added a commit that referenced this issue Jan 6, 2024
…apping (#2491)

* Resolve conflict between parameter-list-spacing and parameter-list-wrapping

Closes #2488
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants