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

Conflicting string-template-indent and function-signature rules #2592

Closed
szedelenyi opened this issue Mar 5, 2024 · 2 comments · Fixed by #2609
Closed

Conflicting string-template-indent and function-signature rules #2592

szedelenyi opened this issue Mar 5, 2024 · 2 comments · Fixed by #2609
Milestone

Comments

@szedelenyi
Copy link

szedelenyi commented Mar 5, 2024

Expected Behavior

Given the following config:

ktlint_function_signature_body_expression_wrapping = default

And the following code:

private fun buildSelectQuery(additionalWhereClause: String = "") =
    """
    SELECT
        $ID,
        $CREATED_AT,
        $CREATED_BY,
        $DELETED,
        $STATE
    FROM $SESSIONS
    WHERE $ID = :$ID
        AND $DELETED = false
        $additionalWhereClause
    """.trimIndent()

I would expect that the function-signature rule is ignored and the string-template-indent rule takes precedence. (Alternatively string-template-indent is ignored, but I feel that string-template-indent should take precedence.)

Observed Behavior

ktlint cannot format the given code, as it either violates function-signature or string-template-indent.

WARN com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine -- Format was not able to resolve all violations which (theoretically) can be autocorrected in file 

Steps to Reproduce

Run ktlint --format on the given snippet.

Your Environment

  • Version of ktlint used: 1.2.1
  • Relevant parts of the .editorconfig settings
max_line_length = 124
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_name_count_to_use_star_import = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647

ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = unset
ktlint_function_signature_body_expression_wrapping = default

# as function signature body expression wrapping is set to `default` instead of `multiline`,
# then it would be inconsistent to enable multiline expression wrapping
ktlint_standard_multiline-expression-wrapping = disabled
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): ktlint-cli 1.2.1
  • Version of Gradle used (if applicable):
  • Operating System and version: macOS 14.2.1
@paul-dingemans
Copy link
Collaborator

Tnx for reporting. This is a bug indeed.

For now you can suppress this as follows:

@Suppress("ktlint:standard:function-signature")
private fun buildSelectQuery(additionalWhereClause: String = "") =
    """
    SELECT
        $ID,
        $CREATED_AT,
        $CREATED_BY,
        $DELETED,
        $STATE
    FROM $SESSIONS
    WHERE $ID = :$ID
        AND $DELETED = false
        $additionalWhereClause
    """.trimIndent()

@paul-dingemans paul-dingemans added this to the 1.2.2 milestone Mar 5, 2024
@szedelenyi
Copy link
Author

Thanks, that's what I did already, but I thought it's worth flagging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants