Skip to content

Trailing comma gets removed if there is only one parameter and it is formatted to be on its own line #461

@hongping-quora

Description

@hongping-quora

Using the ktfmt IntelliJ plugin 1.1.0.47 in Android Studio, setting "Code style" to "Google (internal)"
image
image

  1. The following code with a single parameter will get the trailing comma removed.
import android.content.SharedPreferences

private class AllowlistedDiskReadsSharedPreferences(
  private val wrappedPreferences: SharedPreferences,
) : SharedPreferences by wrappedPreferences
  1. This code with two parameters will not.
import android.content.SharedPreferences

private class AllowlistedDiskReadsSharedPreferences(
  private val wrappedPreferences: SharedPreferences,
  private val wrappedPreferences2: SharedPreferences,
) : SharedPreferences by wrappedPreferences 

Since one of the reasons of using trailing comma is to avoid having to modify an existing line when adding another parameter (https://kotlinlang.org/docs/coding-conventions.html#trailing-commas), perhaps even when there is only one parameter but it has to be on its own line, it should also have a trailing comma?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions