Hello all, I need help with the following code for...
# ktlint
j
Hello all, I need help with the following code formatting. I am not sure what to do: Expected:
Copy code
val navOptions = navOptions {
                popUpTo(navController.graph.findStartDestination().id) {
                    saveState = true
                }

                launchSingleTop = true
                restoreState = true
            }
Result:
Copy code
val navOptions = 
            navOptions {
                popUpTo(navController.graph.findStartDestination().id) {
                    saveState = true
                }

                launchSingleTop = true
                restoreState = true
            }
I do not want
navOptions{}
on a new line.
p
You can disable the multiline-expression rule. But you will loose the ability to run string-template rule. See docs and issue tracker.
j
How do I do this? I am guessing I have to add
Copy code
multiline-expression = disabled
on editorconfig?
p
Almost. It is all in the docs.
j
Here is what my .editorconfig looks like:
Copy code
[*.{kt,kts}]
ktlint_code_style = ktlint_official
insert_final_newline = true
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_ignore_back_ticked_identifier = false
ktlint_standard_multiline-expression-wrapping = disabled
When I run ktlint -F, I get the below error:
Copy code
Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Skipping rule(s) which are depending on a rule which is not loaded. Please check if you need to add additional rule sets before creating an issue.
  - Rule with id 'RuleId(value=standard:string-template-indent)' requires rule with id 'RuleId(value=standard:multiline-expression-wrapping)' to be loaded
        at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
        at com.pinterest.ktlint.cli.internal.KtlintCommandLine.parallel(KtlintCommandLine.kt:708)
        at com.pinterest.ktlint.cli.internal.KtlintCommandLine.parallel$default(KtlintCommandLine.kt:671)
        at com.pinterest.ktlint.cli.internal.KtlintCommandLine.lintFiles(KtlintCommandLine.kt:443)
        at com.pinterest.ktlint.cli.internal.KtlintCommandLine.run(KtlintCommandLine.kt:323)
        at com.pinterest.ktlint.Main.main(Main.kt:35)
Caused by: java.lang.IllegalStateException: Skipping rule(s) which are depending on a rule which is not loaded. Please check if you need to add additional rule sets before creating an issue.
  - Rule with id 'RuleId(value=standard:string-template-indent)' requires rule with id 'RuleId(value=standard:multiline-expression-wrapping)' to be loaded
        at com.pinterest.ktlint.rule.engine.internal.rulefilter.RunAfterRuleFilter.filter(RunAfterRuleFilter.kt:77)
        at com.pinterest.ktlint.rule.engine.internal.rulefilter.RuleFilterKt.applyRuleFilters(RuleFilter.kt:15)
        at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext$Companion.createRuleExecutionContext$ktlint_rule_engine(RuleExecutionContext.kt:192)
        at com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine.format(KtLintRuleEngine.kt:134)
        at com.pinterest.ktlint.cli.internal.KtlintCommandLine.format(KtlintCommandLine.kt:505)
        at com.pinterest.ktlint.cli.internal.KtlintCommandLine.process(KtlintCommandLine.kt:491)
        at com.pinterest.ktlint.cli.internal.KtlintCommandLine.access$process(KtlintCommandLine.kt:59)
        at com.pinterest.ktlint.cli.internal.KtlintCommandLine$lintFiles$3.invoke$lambda$0(KtlintCommandLine.kt:431)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base/java.lang.Thread.run(Thread.java:1583)
Just added:
Copy code
ktlint_standard_string-template-indent = disabled
And it is gone. Thanks. I hope I am not not missing out by disabling this rule. I just want to have minimal formatting impact on the codebase after adding ktlint.