-
Notifications
You must be signed in to change notification settings - Fork 501
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
Add new experimental rule to remove trailing comma's from argument and values lists (#709) #1032
Add new experimental rule to remove trailing comma's from argument and values lists (#709) #1032
Conversation
...xperimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/NoTrailingCommaRule.kt
Outdated
Show resolved
Hide resolved
Tnx for the link to the minimal list of types to be supported. I was not aware that trailing comma's were possible at other places as well. I have added all of them except for COLLECTION_LITERAL_EXPRESSION. I can not create a code example in which this type occurs. |
Isn't the option to disable rules meant for this? Or would you to like this rule to be disbaled by default and that user have to opt-in on the rule? |
For annotation class Annotation(val params: IntArray)
// usage
@Annotation([1, 2,])
val property: Int = 0 Would be nice if we can support this as well.
What I meant is we should decide how the rule behaves based on the intellij editorconfig properties ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true If those are set to |
I solved the COLLECTION_LITERAL_EXPRESSION based on your example. Also the rule is now configured based on the IntelliJ IDEA properties. First I have tried to define a new property analog to
I could not get it working due to some Kotlin to Java interoperability problem. So I have implemented a new parser for the Kotlin Boolean as shown below:
Of course, class above can also be moved to UsesEditorConfigProperties or another new class so that it can be reused for other boolean properties. |
Just curious - what was the exact problem? 🤔 |
Java definition in PropertyType class of ec4j
Copy this to my class resulted, after automatic kotlin conversion, in:
The Looking at the definition of
Kotlin can not distinct the method signatures. Apparently it can not distinct between |
Hey @paul-dingemans , I think the automatic Kotlin conversion produced invalid code. Specifically, if we compare the following Java: PropertyType<Boolean> insert_final_newline = new LowerCasingPropertyType<>( With the following Kotlin: insert_final_newline: PropertyType<Boolean> = LowerCasingPropertyType<Any>( Notice that on the right-hand side of the Java version, the generic type is specified with an empty However, in the Kotlin conversion, a generic type of insert_final_newline: PropertyType<Boolean> = LowerCasingPropertyType( |
Hi @ScottHamper,
Crucial part in this was to define the allowed values as a set instead of an array. |
@paul-dingemans Thank you for taking time to implement this. I'm also interested in this rule. @romtsn Are there any plans on how to go forward with this PR? |
@shashachu Is there any chance that this PR will get merged? |
47ea458
to
9f8ff2e
Compare
Sorry for holding this off for so long @paul-dingemans , I finalized the rule by making it work bi-directional (as mentioned in #1032 (comment)), so it also can add missing trailing commas, if configured like that. Thanks for prior art 👍 |
Given code below:
this should be corrected as:
Closes #709