-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Formatting Regression in KtLint 1.4.1: Violates max_line_length
and Reduces Readability
#2881
Comments
You call the
You have provide a code snippet without providing its virtual path. As of that ktlint can not locate the proper |
Thank you for your suggestion. I updated my code to use // Provide a virtual path for the code snippet as a Path
val virtualPath = kotlinFile.toPath()
// Format and write the file
kotlinFile.writeText(
ktLintRuleEngine.format(Code.fromSnippetWithPath(content, virtualPath)) { _ ->
AutocorrectDecision.ALLOW_AUTOCORRECT
},
) The However, the formatting behavior remains inconsistent with version 1.3.1. Do you have any other suggestions that I can try? |
Suggestions:
|
Unfortunate |
I have no clue why it breaks. When I use your It would be helpful if you can enable debug logging for ktlint, or set a breakpoint at this line and inspect the result. |
Sure, I'm happy to help debugging this issue, just let me know what else can I do to help (I'm also available if you want to have a remote debug session in a call). This is how it looks on 1.3.1: init {
val editorConfigPath = findEditorConfigPath(outputDir)
if (editorConfigPath == null) {
logger.error { "Unable to find .editorconfig file in or above directory ${outputDir.absolutePath}" }
}
ktLintRuleEngine = KtLintRuleEngine(
ruleProviders = ruleProviders,
editorConfigDefaults = editorConfigPath?.let { load(it, ruleProviders.propertyTypes()) }
?: EditorConfigDefaults.EMPTY_EDITOR_CONFIG_DEFAULTS,
)
} Version 1.4.1 looks more or less the same: The Please let me know if I can provide other details that can help to solve this issue. |
I have identified the problem. You have disabled |
@paul-dingemans thank you! I can confirm that after removing But there is still 1 final difference between 1.3.1 and 1.4.1: the latter uses a different spacing for the callback parameters than 1.3.1 and the formatter used by Intellij IDEA: Is there a setting that I can change to restore the same spacing that 1.3.1 and IDEA have? |
No, this behavior is determined by the |
Thank you! Using |
Expected Behavior
When formatting Kotlin code using KtLint 1.4.1, the formatter should produce output that respects the
max_line_length
setting defined in the.editorconfig
file. Additionally, the formatted code should follow Kotlin Coding Conventions for readability, ensuring appropriate line breaks for long function calls.For example, formatting this code:
with
max_line_length=120
should produce this result, as in KtLint 1.3.1:This output is both more readable and adheres to the
max_line_length
constraint.Observed Behavior
Using KtLint 1.4.1, the same input code is formatted as:
This output violates the
max_line_length
constraint and reduces readability.Steps to Reproduce
.editorconfig
file with the following configuration: .editorconfigCommand executed:
Your Environment
.editorconfig
settings:KtLintRuleEngine
directly.The text was updated successfully, but these errors were encountered: