-
Notifications
You must be signed in to change notification settings - Fork 508
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
Formatting with no-semi
rule removes semicolons in enum, even if continues companion object
#1733
Comments
This can be enabled again when this defect is fixed: pinterest/ktlint#1733
similar behavior if there are methods in the enum after the value definitions, not limited to companion objects |
Tnx for reporting. This will be fixed in
Or maybe better, suppress the rule temporarily in |
…st of enum entries is followed by a semicolon then do not remove the semicolon in case it is followed by code element Closes pinterest#1733
* Update ktlint to v0.48.0 * Update imports for ktlint 0.48.0 * Update finding locations for ktlint 0.48.0 * Disable ktlint's NoSemicolons rule This can be enabled again when this defect is fixed: pinterest/ktlint#1733 * Fix new indentation issues raised by ktlint 0.48.0 * Add ContextReceiverMapping rule * Enable ContextReceiverMapping rule on detekt codebase * Fix deprecation warnings
A snapshot release including a fix is available. Read more on https://pinterest.github.io/ktlint/install/snapshot-build/ |
Thanks for quick fix! 👍 |
@paul-dingemans
enum class Foo(val string: String) {
FOO("val1"),
FOO2("val1"),
;
fun any() = "" |
Yes, that is expected behavior. When adding a new enum entry after "FOO2" you don't want that line to appear in the git diff because a comma needs to be added on the line. |
Any way to keep the previous behaviour other than suppressing rules on a per-file basis? Meaning this being a "correct" format: enum class Foo(val string: String) {
FOO("val1"),
FOO2("val1");
fun any() = "" |
There is no such option. If you have set trailing comma's, this is what you get. Also, no such option will be made available in the future. |
Hi, I'm seeing this same problem using 0.48.2. Should I open a separate issue? enum class FileType(val extension: String) {
PB("pb"),
PBTXT("pbtxt");
fun extensionSupported(extension: String): Boolean = this.extension == extension
}
fun File.isPb(): Boolean = FileType.PB.extensionSupported(extension.lowercase()) In order to pass @Suppress("ktlint:no-semi")
internal enum class FileType(val extension: String) {
PB("pb"),
PBTXT("pbtxt"),
;
fun extensionSupported(extension: String): Boolean {
return this.extension == extension
}
}
fun File.isPb(): Boolean = FileType.PB.extensionSupported(extension.lowercase()) Otherwise, I was getting weird errors at the declaration of the extension function
This is my spotless configuration, in case it's relevant
|
In your case you should not suppress the
|
Expected Behavior
Keep the following code as it is.
Observed Behavior
With 0.48.0, using
--format
option removes the semicolon, and it is not a valid Kotlin code.Steps to Reproduce
Run the following command:
When disabling
no-semi
rule, semicolon is not removed.Your Environment
The text was updated successfully, but these errors were encountered: