Hello! Anyone can help me on setting a rule so tha...
# ktlint
l
Hello! Anyone can help me on setting a rule so that the parameters of with(param){} isn't move to a new line when running ktlintFormat?
Copy code
//this:
with(param) {
} 

// instead of this:
with(
    param) {
}
s
that looks like a bug. which version of ktlint?
l
latest
using the latest ktlint-gradle from JLLeitschuh version 11.5.0
Sorry but don't know which version of ktlint it is using.
s
l
I guess I'll try to open an issue there
s
could you file a bug? if you turn on one of these flags (i cannot remember which) and run ktlintCheck it should tell you which rule is making that change
Copy code
debug.set(true)
    verbose.set(true)
l
will try that thanks, and also open an issue.
w
by default ktlint-gradle is still using 0.47.1 of ktlint. bu tyou can set it to a higher version: https://github.com/JLLeitschuh/ktlint-gradle#configuration
s
ah ok thanks for the correction
would be worth checking if it still happens in 0.50 then
l
I tried it by adding
version.set("0.50.0")
, but still the same issue
already added a comment in the issue tracker of the repo. https://github.com/JLLeitschuh/ktlint-gradle/issues/684, it seems that someone else also has the problem in disabling rules
Ok managed to use the debugger to identify which rule to disable. One of them worked (
ktlint_standard_argument_list_wrapping
) but the other that the report identifies as:
Missing newline after "(" (wrapping)
tried to add
ktlint_standard_wrapping
but it doesn't have any effect
p
Rule id
ktlint_standard_argument_list_wrapping
is invalid. It should be
ktlint_standard_argument-list-wrapping
. Don’t know whether it fixes your problem.
l
Sorry @Paul Dingemans I made a mistake while writing here (in the code is the dashes not the underscore). And yes it helped for some of the formatting issues, but for the one regarding my latest post it didn't. I'm referring to the warning:
Missing newline after "(" (wrapping)
and I added
ktlint_standard_wrapping
and it doesn't disappear.
p
Your code sample is too small, or does not contain all relevant details, to reproduce the problem with ktlint CLI. Or I am missing some other relevant context.
l
I've opened an issue here https://github.com/JLLeitschuh/ktlint-gradle/issues/690. I can also try to reproduce it in a dummy project and share with you.
p
Can you carefully inspect your output? In case you only disable the
wrapping
rule, ktlint
0.50.0
throws an exception as some other rules are still enable that depends on this rule:
Copy code
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:trailing-comma-on-call-site)' requires rule with id 'RuleId(value=standard:wrapping)' to be loaded
  - Rule with id 'RuleId(value=standard:trailing-comma-on-declaration-site)' requires rule with id 'RuleId(value=standard:wrapping)' to be loaded
Whenever I disable rules below:
Copy code
ktlint_standard_wrapping = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
your original format is retained but at the cost of loosing a lot of functionalities of those 3 rules. In general, it is better to accept defaults provided by ktlint instead of trying to tweak them based on certain examples that you dislike.
l
@Paul Dingemans here is a dummy project where I replicate my issue: https://github.com/luis-alves/ktor-sample-ktlint
even with your suggested disabled rules:
Copy code
ktlint_standard_wrapping = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
it doesn't work
w
@Luís Alves have you confirmed that other rules from .editorconfig are taking effect?
p
I have verified that Ktlint CLI throws the exceptions in the sample project. How does the ktlint-gradle handle exceptions thrown by the KtlintRuleEngine? They do not seem to be logged while they hold useful information.
l
@wakingrufus yes they do. @Paul Dingemans 🤷‍♂️
@Paul Dingemans found some settings and updated the repo with:
Copy code
ktlint {
    version.set("0.50.0")
    verbose.set(true)
    outputToConsole.set(true)
    coloredOutput.set(true)
    debug.set(true)
    outputColorName.set("RED")
    ignoreFailures.set(false)
}
p
Yes, nice, And now the output contains relevant details about depending rules. Can you check the documentation about this and suggest a change to improve it when missing or unclear?
349 Views