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

experimental:function-return-type-spacing can violate max-line rule #1764

Closed
shashachu opened this issue Jan 4, 2023 · 0 comments · Fixed by #1843
Closed

experimental:function-return-type-spacing can violate max-line rule #1764

shashachu opened this issue Jan 4, 2023 · 0 comments · Fixed by #1843

Comments

@shashachu
Copy link
Contributor

Steps to Reproduce

    fun thisIsAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFunction():
        AndAlsoALongReturnType {

    }

will reformat to:

    fun thisIsAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFunction(): AndAlsoALongReturnType {

    }

Which will violate the max-line-length rule.

The rule may need to make an exception for parameterless functions, or honor the max line length.

Your Environment

  • Version of ktlint used:
  • Relevant parts of the .editorconfig settings
[*.{kt,kts}]
max_line_length = 120
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): ktlint 0.48.1, CLI
@shashachu shashachu added this to the 0.49.0 milestone Jan 4, 2023
paul-dingemans added a commit that referenced this issue Mar 7, 2023
… not result in a max-line-length violation

In case the whitespace contains a newline than replacing it with a single space results in merging the lines to a single line. This rule allows this only when the merged lines entirely fit on a single line.

Suppose that code below does not fit on a single line than this rule no longer emits a violation:
    fun foo():
        String = "some-looooooooooooooooong-string"

See FunctionSignatureRule for reformatting the function like below:
    fun foo(): String =
        "some-looooooooooooooooong-string"

Closes #1764
paul-dingemans added a commit that referenced this issue Mar 8, 2023
… rule (#1843)

* Replacing a whitespace containing a newline after the return type may not result in a max-line-length violation

In case the whitespace contains a newline than replacing it with a single space results in merging the lines to a single line. This rule allows this only when the merged lines entirely fit on a single line.

Suppose that code below does not fit on a single line than this rule no longer emits a violation:
    fun foo():
        String = "some-looooooooooooooooong-string"

See FunctionSignatureRule for reformatting the function like below:
    fun foo(): String =
        "some-looooooooooooooooong-string"

Closes #1764

* Update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant