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

function-literal rule conflict with maximum line length #2743

Closed
mekutluca opened this issue Jul 17, 2024 · 2 comments · Fixed by #2783
Closed

function-literal rule conflict with maximum line length #2743

mekutluca opened this issue Jul 17, 2024 · 2 comments · Fixed by #2783

Comments

@mekutluca
Copy link

Every time the code is formatted with ktlint, the code block below alternates between the two states given at the Observed Behavior.

Expected Behavior

I expect this to be accepted without raising an error.

                                          X
someLongNamedVariable.someField?.let { 
        field 
    ->

Observed Behavior

Below code gives us the error: Newline expected before parameter (standard:function-literal)

                                          X
someLongNamedVariable.someField?.let { field ->

However, below code gives us the error: No newline expected before parameter (standard:function-literal)

                                          X
someLongNamedVariable.someField?.let { 
        field 
    ->

Steps to Reproduce

Example code provided above.

Your Environment

  • Version of ktlint used: 1.3.1
  • Relevant parts of the .editorconfig settings
ktlint_standard_max-line-length = disabled
ktlint_code_style = android_studio
@paul-dingemans
Copy link
Collaborator

The max_line_length setting is invalid. Use either off or unset as value to disable the max line length.

@paul-dingemans
Copy link
Collaborator

The max_line_length setting is invalid. Use either off or unset as value to disable the max line length.

In hindsight the "solution" above is really crude. What I meant to say was that if you really want to disable the max-line-length checking, that you need to set below:

max_line_length = unset

Disabling the max-line-length rule with ktlint_standard_max-line-length = disabled only disables that specific rule. But any other rule that uses the property max_line_length will not be affected by that. In this case the function-literal rule is using the max_line_length to decide whether it should report a violation regarding the positioning of the variables of the lambda.

The "mistake" you made is very understandable and you can not be blamed for it. Even in case it would have been documented properly (which it isn't), this misleads others as well. Ktlint should be more fault tolerant.

paul-dingemans added a commit that referenced this issue Aug 28, 2024
…g the `max-line-length` rule

IMPORTANT: Potential breaking change for API Consumers that provide the `max_line_length` property but not enabling/providing the `max-line-length` rule of the Ktlint standard rule set.

Rules should only consider the maximum line length in case property `max_line_length` is set to a value between 0 and `MAX_INTEGER - 1`, and the `max-line-length` rule is provided to the KtLintRuleEngine, and the `max-line-length` rule is enabled.

It should not be enforced that property `max_line_length` should have value `unset` or `off` whenever the `max-line-length` rule is disabled, or not provided to the KtLintRuleEngine. This property is also used by IntelliJ IDEA to display the right margin where lines should be wrapped. A user should be able to disable enforce max line length wrapping in ktlint, while still seeing the margin line in the editor.

Closes #2743
shashachu pushed a commit that referenced this issue Aug 28, 2024
…abled (#2783)

* Align EditorConfig settings for `max_line_length` and enable/disabling the `max-line-length` rule

IMPORTANT: Potential breaking change for API Consumers that provide the `max_line_length` property but not enabling/providing the `max-line-length` rule of the Ktlint standard rule set.

Rules should only consider the maximum line length in case property `max_line_length` is set to a value between 0 and `MAX_INTEGER - 1`, and the `max-line-length` rule is provided to the KtLintRuleEngine, and the `max-line-length` rule is enabled.

It should not be enforced that property `max_line_length` should have value `unset` or `off` whenever the `max-line-length` rule is disabled, or not provided to the KtLintRuleEngine. This property is also used by IntelliJ IDEA to display the right margin where lines should be wrapped. A user should be able to disable enforce max line length wrapping in ktlint, while still seeing the margin line in the editor.

Closes #2743

* Update documentation
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