Skip to content
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

Rule suggestion: prefer emptyList() over listOf() #2878

Open
FloEdelmann opened this issue Nov 25, 2024 · 1 comment
Open

Rule suggestion: prefer emptyList() over listOf() #2878

FloEdelmann opened this issue Nov 25, 2024 · 1 comment

Comments

@FloEdelmann
Copy link
Contributor

FloEdelmann commented Nov 25, 2024

Expected Rule behavior

// Should fail:
val foo: List<String> = listOf()
val bar = listOf<String>()

// Should pass:
val baz: List<String> = emptyList()
val boo = emptyList<String>()

val far = mutableListOf<String>()
val faz = listOf("foo")

Additional information

@paul-dingemans
Copy link
Collaborator

I have some doubts whether this should be a Ktlint rule. It is not really related to lint/formatting but more an inspection kind of rule. If such a rule would be added it should be a bit more generic and also take setOf() and mapOf into account. As this is not mentioned in the style guides, it can only be added and activated by default in ktlint_official code style. For other code styles it will need to be enabled explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants