diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index ec428fa5e39..7c66a7443f4 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -2922,6 +2922,15 @@ language="kotlin" /> + + + +This inspection reports commas which have a different position from the one recommended in the style guide, +and offers to reformat them. + + diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/TrailingCommaInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/TrailingCommaInspection.kt new file mode 100644 index 00000000000..0fadaf9f99b --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/TrailingCommaInspection.kt @@ -0,0 +1,73 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.inspections + +import com.intellij.codeInspection.ProblemsHolder +import com.intellij.openapi.util.TextRange +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiElementVisitor +import org.jetbrains.kotlin.idea.formatter.TrailingCommaPostFormatProcessor.Companion.findInvalidCommas +import org.jetbrains.kotlin.idea.formatter.TrailingCommaPostFormatProcessor.Companion.needComma +import org.jetbrains.kotlin.idea.formatter.TrailingCommaPostFormatProcessor.Companion.trailingCommaAllowedInModule +import org.jetbrains.kotlin.idea.formatter.TrailingCommaPostFormatProcessor.Companion.trailingCommaOrLastElement +import org.jetbrains.kotlin.idea.formatter.TrailingCommaVisitor +import org.jetbrains.kotlin.idea.formatter.isComma +import org.jetbrains.kotlin.idea.formatter.leafIgnoringWhitespaceAndComments +import org.jetbrains.kotlin.idea.quickfix.ReformatQuickFix +import org.jetbrains.kotlin.psi.KtElement +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.nextLeaf +import org.jetbrains.kotlin.psi.psiUtil.startOffset + +class TrailingCommaInspection : AbstractKotlinInspection() { + override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = object : TrailingCommaVisitor() { + override val recursively: Boolean = false + + override fun process(commaOwner: KtElement) { + checkCommaPosition(commaOwner) + checkTrailingComma(commaOwner) + } + + private fun checkCommaPosition(commaOwner: KtElement) { + if (!needComma(commaOwner, checkExistingTrailingComma = true)) return + for (invalidComma in findInvalidCommas(commaOwner)) { + reportProblem(invalidComma, "Comma loses the advantages in this position", "Fix comma position") + } + } + + private fun checkTrailingComma(commaOwner: KtElement) { + val trailingCommaOrLastElement = trailingCommaOrLastElement(commaOwner) ?: return + if (needComma(commaOwner, checkExistingTrailingComma = false)) { + if (!trailingCommaAllowedInModule(commaOwner) || trailingCommaOrLastElement.isComma) return + reportProblem(trailingCommaOrLastElement, "Missing trailing comma", "Add trailing comma") + } else if (!needComma(commaOwner, checkExistingTrailingComma = true)) { + if (!trailingCommaOrLastElement.isComma) return + reportProblem(trailingCommaOrLastElement, "Redundant trailing comma", "Remove trailing comma") + } + } + + private fun reportProblem(commaOrElement: PsiElement, message: String, fixMessage: String) { + val commaOwner = commaOrElement.parent + holder.registerProblem( + commaOwner, + commaOrElement.textRangeOfLastSymbol.shiftLeft(commaOwner.startOffset), + message, + ReformatQuickFix(fixMessage) + ) + } + + private val PsiElement.textRangeOfLastSymbol: TextRange + get() { + val textRange = textRange + if (textRange.length <= 1) return textRange + + return nextLeaf()?.leafIgnoringWhitespaceAndComments(false)?.endOffset?.takeIf { it > 0 }?.let { + TextRange.create(it - 1, it).intersection(textRange) + } ?: TextRange.create(textRange.endOffset - 1, textRange.endOffset) + } + } + +} diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReformatQuickFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReformatQuickFix.kt new file mode 100644 index 00000000000..22ddfff0155 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReformatQuickFix.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.quickfix + +import com.intellij.codeInspection.LocalQuickFix +import com.intellij.codeInspection.ProblemDescriptor +import com.intellij.openapi.project.Project +import com.intellij.psi.codeStyle.CodeStyleManager + +class ReformatQuickFix(val description: String) : LocalQuickFix { + override fun getName(): String = description + + override fun getFamilyName(): String = name + + override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + descriptor.psiElement?.let { + CodeStyleManager.getInstance(project).reformat(it) + } + } +} diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/ArgumentList.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/ArgumentList.kt new file mode 100644 index 00000000000..da169db0254 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/ArgumentList.kt @@ -0,0 +1,225 @@ +fun foo() { + testtest(foofoo, foofoo, foofoo, + foofoo, bar) + + testtest( + foofoo, foofoo, foofoo, foofoo, bar + ) + + testtest(foofoo, foofoo, foofoo, foofoo, bar + ) + + testtest(foofoo, foofoo, foofoo, foofoo, + bar + ) + + testtest(foofoo + ) + + testtest( + foofoo) + + testtest( + foofoo + ) + + testtest(foofoo,) + + testtest(foofoo, testtest(testtest(foofoo))) + + testtest(foofoo, fososos, testtest(testtest(foofoo)),) + + testtest(foofoo, testtest(testtest(foofoo,)), testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), testsa) + + useCallable("A", Callable { println("Hello world") }) + + useCallable("B", "C", Callable { + println("Hello world") + }, Callable { + println("Hello world") + }) + + useCallable(Callable { println("Hello world") }) + + useCallable(Callable { println("Hello world") },) + + useCallable(Callable { println("Hello world") } + ) + + useCallable(Callable { println("Hello world") }){ + + } + + useCallable( + Callable { println("Hello world") }) + + useCallable("A", { println("Hello world") }) + + useCallable("B", "C", { + println("Hello world") + }, { + println("Hello world") + }) + + useCallable({ println("Hello world") }) + + useCallable({ println("Hello world") },) + + useCallable({ println("Hello world") } + ) + + useCallable({ println("Hello world") }){ + + } + + useCallable( + { println("Hello world") }) + + useCallable("A", foo() { println("Hello world") }) + + useCallable("B", "C", foo() { + println("Hello world") + }, foo() { + println("Hello world") + }) + + useCallable(foo() { println("Hello world") }) + + useCallable(foo() { println("Hello world") },) + + useCallable(foo() { println("Hello world") } + ) + + useCallable(foo() { println("Hello world") }) { + + } + + useCallable( + foo() { println("Hello world") }) + + useCallable("A", object : Callable { override fun call() { println("Hello world") } }) + + useCallable("A", object : Callable { + override fun call() { + println("Hello world") + } + }) + + useCallable("B", "C", object : Callable { override fun call() { println("Hello world") } }, foo() { + println("Hello world") + }) + + useCallable(object : Callable { override fun call() { println("Hello world") } }) + + useCallable(object : Callable { override fun call() { println("Hello world") } },) + + useCallable(object : Callable { override fun call() { println("Hello world") } } + ) + + useCallable(object : Callable { override fun call() { println("Hello world") } }) { + + } + + useCallable( + object : Callable { override fun call() { println("Hello world") } }) + + testtest( + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + ) + + testtest(/* + */foofoo, foofoo, foofoo, /* + + */ + foofoo, bar) + + testtest(foofoo, foofoo, foofoo, foofoo, bar/* + */) + + testtest(foofoo, foofoo, foofoo, foofoo, bar // awdawda + ) + + testtest(foofoo, foofoo, foofoo, foofoo, /* + + */ + bar + ) + + testtest(foofoo // fd + ) + + testtest( /**/ + foofoo + ) + + testtest(foofoo,/**/) + + testtest(foofoo, foofoo, foofoo, foofoo/* + */ , /* */ bar + ) + + testtest(foofoo // fd + ) + + testtest( /**/ + foofoo + ) + + testtest(foofoo,/**/) + + testtest(foofoo, fososos,/* + */ testtest(testtest(foofoo)),) + + testtest(foofoo, testtest(testtest(foofoo,)), /**/testsa) + + testtest(foofoo, testtest(testtest(foofoo,))/* */ , /**/testsa) + + testtest(foofoo, testtest(testtest(foofoo,))/* + */ ,testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), /**/testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), /* + */testsa) + + useCallable("B", "C", Callable { + println("Hello world") + }, /* */ Callable { + println("Hello world") + }) + + useCallable(Callable { println("Hello world") } // ffd + ) + + useCallable(object : Callable { override fun call() { println("Hello world") } + },) + + useCallable(foo() { println("Hello world") + },) + + useCallable({ + println("Hello world") },) + + useCallable(Callable { println("Hello world") } + ,) + + testtest(foofoo, testtest(testtest( + foofoo,)), testsa) + + testtest(foofoo, fososos, testtest(testtest(foofoo)) + ,) + +} + +fun test() { + baz( + f = fun(it: Int): String = "$it" /*dwdwd + */, + name = "" /* + */, + ) +} diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/CollectionLiteralInAnnotation.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/CollectionLiteralInAnnotation.kt new file mode 100644 index 00000000000..02657111dc4 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/CollectionLiteralInAnnotation.kt @@ -0,0 +1,112 @@ +@Anno([1]) +fun a() = Unit + +@Anno([1,]) +fun a() = Unit + +@Anno([1 + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 ]) +fun a() = Unit + +@Anno([1,2]) +fun a() = Unit + +@Anno([1, 2,]) +fun a() = Unit + +@Anno([1, 2 + ]) +fun a() = Unit + +@Anno([ + 1, 2, ]) +fun a() = Unit + +@Anno([ + 1, 2 ]) +fun a() = Unit + +@Anno([1, 2, 2]) +fun a() = Unit + +@Anno([1, 2, 2,]) +fun a() = Unit + +@Anno(["1" + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 , 2 , 2 ]) +fun a() = Unit + +@Anno([1/* + */]) +fun a() = Unit + +@Anno([1, //dw + ]) +fun a() = Unit + +@Anno([1 // ds + ]) +fun a() = Unit + +@Anno([/* + */ // d + 1/* + */,/* + */ ]) +fun a() = Unit + +@Anno([ + /* + */ 1 ]) +fun a() = Unit + +@Anno([1/* + */,2]) +fun a() = Unit + +@Anno([1, 2/* + */,/* + */]) +fun a() = Unit + +@Anno([/* + */1, 2 + ]) +fun a() = Unit + +@Anno(["1" + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 , 2 /* + */ ]) +fun a() = Unit + +@Component( + modules = [ + AppModule::class, DataModule::class, + DomainModule::class + ], +) +fun b() = Unit \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/DestructionDeclarationsInLambda.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/DestructionDeclarationsInLambda.kt new file mode 100644 index 00000000000..21170b923ee --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/DestructionDeclarationsInLambda.kt @@ -0,0 +1,64 @@ +val x: (Pair, Int) -> Unit = { (x, y,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, + y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { ( + x, + y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { ( + x // adw + ,y,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x /* val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +}*/,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y/**/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y/* +*/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (/**/x /**/ /* +*/, // awdawd + y/* +*/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { + (/**/x /**/ /* +*/, // awdawd + y/* +*/), + z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y,), + z, -> + println(x) +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/Enum.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/Enum.kt new file mode 100644 index 00000000000..207fda00b4b --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/Enum.kt @@ -0,0 +1,38 @@ +enum class Enum1 { + A, B,; +} + +enum class Enum2 { + A, B; +} + +enum class Enum3 { + A, B + ; +} + +enum class Enum4 { + A, B, +} + +enum class Enum5 { + A, B, +} + +enum class Enum6(val a: Int) { + A( + 1 + ), B, +} + +enum class Enum7(val a: Int) { + A( + 1 + ), B,; +} + +enum class Enum8(val a: Int) { + A( + 1 + ), B; +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/IndicesAccess.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/IndicesAccess.kt new file mode 100644 index 00000000000..19e5ab15d5d --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/IndicesAccess.kt @@ -0,0 +1,176 @@ +fun foo() { + testtest[foofoo, foofoo, foofoo, + foofoo, bar] + + testtest[ + foofoo, foofoo, foofoo, foofoo, bar + ] + + testtest[foofoo, foofoo, foofoo, foofoo, bar + ] + + testtest[foofoo, foofoo, foofoo, foofoo, + bar + ] + + testtest[foofoo + ] + + testtest[ + foofoo] + + testtest[ + foofoo + ] + + testtest[foofoo,] + + testtest[foofoo, testtest[testtest[foofoo]]] + + testtest[foofoo, fososos, + testtest[testtest[foofoo]],] + + testtest[foofoo, testtest[testtest[foofoo,]], testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], testsa] + + useCallable["A", Callable { println["Hello world"] }] + + useCallable["B", "C", Callable { + println["Hello world"] + }, Callable { + println["Hello world"] + }] + + useCallable[Callable { println["Hello world"] }] + + useCallable[Callable { println["Hello world"] },] + + useCallable[Callable { + println["Hello world"] },] + + useCallable[Callable { println["Hello world"] } + ] + + useCallable[Callable { println["Hello world"] }]{ + + } + + useCallable[ + Callable { println["Hello world"] }] + + useCallable["A", { println["Hello world"] }] + + useCallable["B", "C", { + println["Hello world"] + }, { + println["Hello world"] + }] + + useCallable[{ println["Hello world"] }] + + useCallable[{ println["Hello world"] },] + + useCallable[{ println["Hello world"] } + ,] + + useCallable[{ println["Hello world"] } + ] + + useCallable[ + { println["Hello world"] }] + + useCallable["A", object : Callable { override fun call() { println["Hello world"] } }] + + useCallable["A", object : Callable { + override fun call() { + println["Hello world"] + } + }] + + useCallable["B", "C", object : Callable { override fun call() { println["Hello world"] } }, foo[0,]] + + useCallable[object : Callable { override fun call() { println["Hello world"] } }] + + useCallable[object : Callable { override fun call() { println["Hello world"] } },] + + useCallable[object : Callable { override fun call() { println["Hello world"] } } + ] + + useCallable[object : Callable { override fun call() { println["Hello world"] } }] { + + } + + useCallable[ + object : Callable { override fun call() { println["Hello world"] } }] + + testtest[ + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + ] + + testtest[/* + */foofoo, foofoo, foofoo, /* + + */ + foofoo, bar] + + testtest[foofoo, foofoo, foofoo, foofoo, bar/* + */] + + testtest[foofoo, foofoo, foofoo, foofoo, bar // awdawda + ] + + testtest[foofoo, foofoo, foofoo, foofoo, /* + + */ + bar + ] + + testtest[foofoo // fd + ] + + testtest[ /**/ + foofoo + ] + + testtest[foofoo,/**/] + + testtest[foofoo, foofoo, foofoo, foofoo/* + */ , /* */ bar + ] + + testtest[foofoo // fd + ] + + testtest[ /**/ + foofoo + ] + + testtest[foofoo,/**/] + + testtest[foofoo, fososos,/* + */ testtest[testtest[foofoo]],] + + testtest[foofoo, testtest[testtest[foofoo,]], /**/testsa] + + testtest[foofoo, testtest[testtest[foofoo,]]/* */ , /**/testsa] + + testtest[foofoo, testtest[testtest[foofoo,]]/* + */ ,testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], /**/testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], /* + */testsa] + + useCallable["B", "C", Callable { + println["Hello world"] + }, /* */ Callable { + println["Hello world"] + }] + + useCallable[Callable { println["Hello world"] } // ffd + ] +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/LambdaParameterList.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/LambdaParameterList.kt new file mode 100644 index 00000000000..6ac3c373f33 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/LambdaParameterList.kt @@ -0,0 +1,190 @@ +val x = { + x: Comparable>, + y: String, +-> + println("1") + } + +val x = {x: Comparable>, y: String-> + println("1") + } + +val x = {x: String, y +: String-> + println("1") + } + +val x = { + x: String, + y: String +-> + println("1") + } + +val x = { + x: String, + y: Comparable>,-> + println("1") + } + +val x = { + x: Comparable>, + y: String + ,-> + println("1") + } + +val x = { + x: String, + y: Comparable>, + z: String, +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String,-> + println("1") + } + +val x = { + x: String, + y: String, + z: String + ,-> + println("1") + } + +val x = { + x: String, +-> + println("1") + } + +val x = { + x: String +-> + println("1") + } + +val x = { + x: String,-> + println("1") + } + +val x = { + x: String + ,-> + println("1") + } + +val x = { + x: String , + y: String, +-> + println("1") + } + +val x = { + x: String, + z: String +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String ,-> + println("1") + } + +val x = { + x: String, + z: String + , -> + println("1") + } + +val x = { + x, y: String, + z: String + , -> + println("1") + } + +val x = { + x: String, y: String, z: String +-> + println("1") + } + +val x = { + z: String, v: Comparable>, + +-> + println("1") + } + +val x = {x: String, + y: Comparable>, +-> + println("1") + } + +val x = { + x: Int +-> + println("1") + } + +val x = { + x: String, y: String + , /* */ z: String +-> + println("1") + } + +val x = { + x: String, y: String + /* */, /* */ z: String +-> + println("1") + }() + +val x = { + x: String, /* + */ y: String, + z: String ,-> + println("1") + } + +val x = { + x: String, y: String , z: String /* + */ + , -> + println("1") + } + +val x = { + x: Comparable>, y: String, + z: String + , -> + println("1") + } + +val x = { + x: String, y: String, z: String +-> + println("1") + } diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/LambdaValueParameters.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/LambdaValueParameters.kt new file mode 100644 index 00000000000..d034a157c85 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/LambdaValueParameters.kt @@ -0,0 +1,83 @@ +fun main() { + val x: ( + y: Comparable>, + z: Iterable> // trailing comma + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + z: Iterable> + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>,) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>, + ) -> Int = { + 10 + } + + val x: (y: Comparable>) -> Int = { + 10 + } + + val x: (y: Comparable>,) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>) -> Int = { + 10 + } + + val x: ( + y: Comparable>, // + z: Iterable> // /**/ + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable> + // wd + ) -> Int = { + 10 + } + + val x: (y: Comparable>/* + */, z: Iterable>, /* // + */) -> Int = { + 10 + } + + val x: (/**/y: Comparable>/**/) -> Int = { + 10 + } + + val x: (y: Comparable>/**/,) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( /* + */y: Comparable>) -> Int = { + 10 + } +} diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/MultiVariableDeclaration.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/MultiVariableDeclaration.kt new file mode 100644 index 00000000000..48b97ed2bf0 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/MultiVariableDeclaration.kt @@ -0,0 +1,99 @@ +fun test() { + val (a, b) = 1 to 2 + + val (a, b) = 1 to + 2 + + val (a, b) = 1 + to + 2 + + + val (a, b,) = 1 to 2 + + val (a,) = + b + + val (a, + ) = + b + + val (a + ) = + b + + val (a,) = b + + val ( + a,) = b + + val (a, b + ) = 1 to 2 + + val (a, + b) = 1 to 2 + + val ( + a, b + ) = 1 to 2 + + val ( + a, b, + ) = 1 to 2 + + val (a, b, c, + d, f + ) = 1 to 2 + + val (a, b, c, + d, f, + ) = 1 to 2 + + val (a, b/**/) = 1 to 2 + + val (a, /**/b/**/) /**/=/**/ 1 to + 2 + + val (a,/**/ b) = 1 + to + 2 + + val (a, b/**/,) = 1 to 2 + + val (a/**/, b/**/,/**/) = 1 to 2 + + val (a/**/,/**/) = + b + + val (a,) = b + + val (a, b/**/ + ) = 1 to 2 + + val (a, b// awd + ) = 1 to 2 + + val (a,/**/ b /**/ // awd + ) = 1 to 2 + + val (a, // ad + /**/b) = 1 to 2 + + val ( + a, b // fe + /**/)/**/ = 1 to 2 + + val ( + a, b, // awd + ) = 1 to 2 + + val (a, b, c, + d, f // awd + /* + */) = 1 to 2 + + val (a, b, c, + d, f // awd + , + ) = 1 to 2 +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/ParameterList.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/ParameterList.kt new file mode 100644 index 00000000000..cb00f14928d --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/ParameterList.kt @@ -0,0 +1,458 @@ +class A1 { + val x: String + val y: String + + constructor( + x: String, + y: String, + ) { + this.x = x + this.y = y + } +} + +class B1 { + val x: String + val y: String + + constructor( + x: String, + y: String + ) { + this.x = x + this.y = y + } +} + +class C1 { + val x: String + val y: String + + constructor( + x: String, + y: String,) { + this.x = x + this.y = y + } +} + +class D1 { + val x: String + val y: String + + constructor( + x: String, + y: String + ,) { + this.x = x + this.y = y + } +} + +class A2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String, + ) { + this.x = x + this.y = y + this.z = z + } +} + +class B2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String + ) { + this.x = x + this.y = y + this.z = z + } +} + +class C2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String,) { + this.x = x + this.y = y + this.z = z + } +} + +class D2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String + ,) { + this.x = x + this.y = y + this.z = z + } +} + +class A3 { + val x: String + + constructor(x: String,) { + this.x = x + } +} + +class B3 { + val x: String + + constructor(x: String) { + this.x = x + } +} + +class C3 { + val x: String + + constructor( + x: String,) { + this.x = x + } +} + +class D3 { + val x: String + + constructor( + x: String + ,) { + this.x = x + } +} + +class E1 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, z: String,) { + this.x = x + this.y = y + this.z = z + } +} + +class E2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, z: String) { + this.x = x + this.y = y + this.z = z + } +} +class A1( + val x: String, + y: String, +) + +class B1( + val x: String, + val y: String +) + +class C1( + val x: String, + val y: String,) + +class D1( + val x: String, + val y: String + ,) + +class A2( + val x: String, + val y: String, + val z: String, +) + +class B2( + val x: String, + val y: String, + val z: String +) + +class C2( + val x: String, + val y: String, + val z: String,) + +class D2( + val x: String, + val y: String, + val z: String + ,) + +class A3( + val x: String, +) + +class B3( + val x: String +) + +class C3( + val x: String,) + +class D3( + val x: String + ,) + +class A4( + val x: String , + val y: String, + val z: String , +) + +class B4( + val x: String, + val y: String, + val z: String +) + +class C4( + val x: String, + val y: String, + val z: String ,) + +class D4( + val x: String, + val y: String, + val z: String + , ) + +class E1( + val x: String, val y: String, + val z: String + , ) + +class E2( + val x: String, val y: String, val z: String +) + +class C( + z: String, val v: Int, val x: Int = + 42, val y: Int = + 42 +) + +val foo1: (Int, Int) -> Int = fun( + x, + y, +): Int = 42 + +val foo2: (Int, Int) -> Int = fun( + x, + y +): Int { + return x + y +} + +val foo3: (Int, Int) -> Int = fun( + x, y, +): Int { + return x + y +} + +val foo4: (Int) -> Int = fun( + x, +): Int = 42 + +val foo5: (Int) -> Int = fun( + x +): Int = 42 + +val foo6: (Int) -> Int = fun(x,): Int = 42 + +val foo7: (Int) -> Int = fun(x): Int = 42 + +val foo8: (Int, Int, Int) -> Int = fun (x, y: Int, z,): Int { + return x + y +} + +val foo9: (Int, Int, Int) -> Int = fun ( + x, + y: Int, + z, +): Int = 42 + +val foo10: (Int, Int, Int) -> Int = fun ( + x, + y: Int, + z: Int +): Int = 43 + +val foo10 = fun ( + x: Int, + y: Int, + z: Int +): Int = 43 + +val foo11 = fun ( + x: Int, + y: Int, + z: Int, +): Int = 43 + +val foo12 = fun ( + x: Int, y: Int, z: Int, +): Int = 43 + +val foo13 = fun (x: Int, y: Int, z: Int, +): Int = 43 + +val foo14 = fun (x: Int, y: Int, z: Int + ,): Int = 43 + +fun a1( + x: String, + y: String, +) = Unit + +fun b1( + x: String, + y: String +) = Unit + +fun c1( + x: String, + y: String,) = Unit + +fun d1( + x: String, + y: String + ,) = Unit + +fun a2( + x: String, + y: String, + z: String, +) = Unit + +fun b2( + x: String, + y: String, + z: String +) = Unit + +fun c2( + x: String, + y: String, + z: String,) = Unit + +fun d2( + x: String, + y: String, + z: String + ,) = Unit + +fun a3( + x: String, +) = Unit + +fun b3( + x: String +) = Unit + +fun c3( + x: String,) = Unit + +fun d3( + x: String + ,) = Unit + +fun a4( + x: String + , + y: String, + z: String , +) = Unit + +fun b4( + x: String, + y: String, + z: String +) = Unit + +fun c4(x: String, + y: String, + z: String ,) = Unit + +fun d4( + x: String, + y: String, + z: String + , ) = Unit + +fun foo( + x: Int = + 42 +) { +} + +class C( + val x: Int = + 42 +) + +class G( + val x: String, val y: String + = "", /* */ val z: String +) + +class G( + val x: String, val y: String + = "" /* */, /* */ val z: String +) + +class H( + val x: String, /* + */ val y: String, + val z: String ,) + +class J( + val x: String, val y: String , val z: String /* + */ + , ) + +class K( + val x: String, val y: String, + val z: String + , ) + +class L( + val x: String, val y: String, val z: String // adwd +) diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/TypeArgumentList.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/TypeArgumentList.kt new file mode 100644 index 00000000000..e46f5c1f3ac --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/TypeArgumentList.kt @@ -0,0 +1,113 @@ +fun foo() { + testtest, + >, + testsa, + >() + + testtest() + + testtest< + foofoo, foofoo, foofoo, foofoo, bar + >() + + testtest() + + testtest() + + testtest() + + testtest< + foofoo>() + + testtest< + foofoo + >() + + testtest() + + testtest>>() + + testtest>,>() + + testtest> + ,>() + + testtest>, testsa>() + + testtest>, testsa>() + + testtest< + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + >() + + testtest() + + testtest() + + testtest() + + testtest() + + testtest() + + testtest< /**/ + foofoo + >() + + testtest() + + testtest() + + testtest() + + testtest< /**/ + foofoo + >() + + testtest() + + testtest() + + testtest< + foofoo,/**/>() + + testtest>,>() + + testtest>, /**/testsa>() + + testtest>/* */ , /**/testsa>() + + testtest>/* + */ ,testsa>() + + testtest>, /**/testsa>() + + testtest>, /* + */testsa>() +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/TypeParameterList.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/TypeParameterList.kt new file mode 100644 index 00000000000..5e01f5ff057 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/TypeParameterList.kt @@ -0,0 +1,261 @@ +class A1< + x: String, + y: String, +> + +class F + +class F2 + +class B1< + x: String, + y: String +> + +class C1< + x: String, + y: String,> + +class D1< + x: String, + y: String + ,> + +class A2< + x: String, + y: String, + z: String, +> + +class B2< + x: String, + y: String, + z: String +> + +class C2< + x: String, + y: String, + z: String,> + +class D2< + x: String, + y: String, + z: String + ,> + +class A3< + x: String, +> + +class B3< + x: String +> + +class C3< + x: String,> + +class D3< + x: String + ,> + +class A4< + x: String , + y: String, + z , +> + +class B4< + x: String, + y, + z: String +> + +class C4< + x: String, + y: String, + z: String ,> + +class D4< + x: String, + y, + z: String + , > + +class E1< + x, y: String, + z: String + , > + +class E2< + x: String, y: String, z: String +> + +class C< + z: String, v + +> + +fun a1() = Unit + +fun b1() = Unit + +fun < + x: String, + y: String,> c1() = Unit + +fun < + x: String, + y: String + ,> d1() = Unit + +fun < + x: String, + y: String, + z: String, +> a2() = Unit + +fun < + x: String, + y: String, + z: String +> b2() = Unit + +fun < + x: String, + y: String, + z: String,> c2() = Unit + +fun < + x: String, + y: String, + z: String + ,> d2() = Unit + +fun < + x: String, +> a3() = Unit + +fun < + x: String +> b3() = Unit + +fun < + x: String,> c3() = Unit + +fun < + x: String + ,> d3() = Unit + +fun < + x: String + , + y: String, + z: String , +> a4() = Unit + +fun < + x: String, + y: String, + z: String +> b4() = Unit + +fun c4() = Unit + +fun < + x: String, + y: String, + z: String + , > d4() = Unit + +fun < + x +> foo() { +} + +fun ag() { + +} + +fun ag() { + +} + +fun < + T> ag() { + +} + +class C< + x: Int +> + +class G< + x: String, y: String + , /* */ z: String +> + +class G< + x: String, y: String + /* */, /* */ z: String +>() + +class H< + x: String, /* + */ y: String, + z: String ,> + +class J< + x: String, y: String , z: String /* + */ + , > + +class K< + x: String, y: String, + z: String + , > + +class L< + x: String, y: String, z: String +> + +class C< + x: Int // adad +> + +class G< + x: String, y: String + , /* */ z: String // adad +> + +class G< + x: String, y: String + /* */, /* */ z: String /**/, +>() + +class H< + x: String, /* + */ y: String, + z: String /* + */ ,> + +class J< + x: String, y: String , z: String /* + */ + , /**/ > + +class K< + x: String, y: String, + z: String // aw + , > + +class L< + x: String, y: String, z: String //awd +> diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/WhenEntry.kt b/idea/testData/inspections/trailingCommaOffWithCodeStyle/WhenEntry.kt new file mode 100644 index 00000000000..0e9819b8cf6 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/WhenEntry.kt @@ -0,0 +1,75 @@ +fun foo(x: Any) = when (x) { + Comparable::class, Iterable::class, String::class, // trailing comma + -> println(1) + else -> println(3) +} + +fun foo(x: Any) { + when (x) { + Comparable::class, Iterable::class, String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, + String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, + String::class /*// trailing comma*/, -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + 1 -> { + + } + else -> println(3) + } + + when (x) { + 1, -> { + + } + else -> println(3) + } + + when (x) { + 1 + -> { + + } + else -> println(3) + } + + when (x) { + 1, 2, + 3 /**/ -> { + + } + else -> println(3) + } + + when (val c = x) { + 1, 2, + 3 /**/ -> { + + } + else -> println(3) + } + + when { + x in coll + -> { + + } + else -> println(3) + } +} diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/inspectionData/expected.xml b/idea/testData/inspections/trailingCommaOffWithCodeStyle/inspectionData/expected.xml new file mode 100644 index 00000000000..a4aec60ce1a --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/inspectionData/expected.xml @@ -0,0 +1,875 @@ + + + ArgumentList.kt + 26 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 30 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 32 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 68 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 90 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 116 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 131 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ArgumentList.kt + 159 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 162 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ArgumentList.kt + 172 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 177 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 179 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 181 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 182 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ArgumentList.kt + 184 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 186 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 221 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ArgumentList.kt + 223 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + CollectionLiteralInAnnotation.kt + 4 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 22 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 40 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 70 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + CollectionLiteralInAnnotation.kt + 80 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + CollectionLiteralInAnnotation.kt + 84 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 1 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 1 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 5 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 22 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 28 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 32 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 36 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 54 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 26 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 35 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 47 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 72 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 91 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 95 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 110 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + IndicesAccess.kt + 138 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 141 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + IndicesAccess.kt + 151 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 156 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 158 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 160 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 161 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + IndicesAccess.kt + 163 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 165 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaParameterList.kt + 81 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaParameterList.kt + 160 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + LambdaParameterList.kt + 175 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + LambdaValueParameters.kt + 20 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaValueParameters.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaValueParameters.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + LambdaValueParameters.kt + 70 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 12 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 14 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 25 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 63 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 65 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 68 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 97 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ParameterList.kt + 118 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 298 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 302 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 438 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ParameterList.kt + 449 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeArgumentList.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 38 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 43 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 45 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 50 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeArgumentList.kt + 78 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 81 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeArgumentList.kt + 91 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 102 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 104 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 106 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 107 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeArgumentList.kt + 109 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 111 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeParameterList.kt + 187 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeParameterList.kt + 207 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 218 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 240 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 240 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 247 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 252 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 257 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + WhenEntry.kt + 21 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + WhenEntry.kt + 38 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/inspectionData/inspections.test b/idea/testData/inspections/trailingCommaOffWithCodeStyle/inspectionData/inspections.test new file mode 100644 index 00000000000..ac34a229acd --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/inspectionData/inspections.test @@ -0,0 +1,3 @@ +// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.TrailingCommaInspection +// COMPILER_ARGUMENTS: -XXLanguage:-TrailingCommas +// SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/ArgumentList.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/ArgumentList.kt new file mode 100644 index 00000000000..da169db0254 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/ArgumentList.kt @@ -0,0 +1,225 @@ +fun foo() { + testtest(foofoo, foofoo, foofoo, + foofoo, bar) + + testtest( + foofoo, foofoo, foofoo, foofoo, bar + ) + + testtest(foofoo, foofoo, foofoo, foofoo, bar + ) + + testtest(foofoo, foofoo, foofoo, foofoo, + bar + ) + + testtest(foofoo + ) + + testtest( + foofoo) + + testtest( + foofoo + ) + + testtest(foofoo,) + + testtest(foofoo, testtest(testtest(foofoo))) + + testtest(foofoo, fososos, testtest(testtest(foofoo)),) + + testtest(foofoo, testtest(testtest(foofoo,)), testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), testsa) + + useCallable("A", Callable { println("Hello world") }) + + useCallable("B", "C", Callable { + println("Hello world") + }, Callable { + println("Hello world") + }) + + useCallable(Callable { println("Hello world") }) + + useCallable(Callable { println("Hello world") },) + + useCallable(Callable { println("Hello world") } + ) + + useCallable(Callable { println("Hello world") }){ + + } + + useCallable( + Callable { println("Hello world") }) + + useCallable("A", { println("Hello world") }) + + useCallable("B", "C", { + println("Hello world") + }, { + println("Hello world") + }) + + useCallable({ println("Hello world") }) + + useCallable({ println("Hello world") },) + + useCallable({ println("Hello world") } + ) + + useCallable({ println("Hello world") }){ + + } + + useCallable( + { println("Hello world") }) + + useCallable("A", foo() { println("Hello world") }) + + useCallable("B", "C", foo() { + println("Hello world") + }, foo() { + println("Hello world") + }) + + useCallable(foo() { println("Hello world") }) + + useCallable(foo() { println("Hello world") },) + + useCallable(foo() { println("Hello world") } + ) + + useCallable(foo() { println("Hello world") }) { + + } + + useCallable( + foo() { println("Hello world") }) + + useCallable("A", object : Callable { override fun call() { println("Hello world") } }) + + useCallable("A", object : Callable { + override fun call() { + println("Hello world") + } + }) + + useCallable("B", "C", object : Callable { override fun call() { println("Hello world") } }, foo() { + println("Hello world") + }) + + useCallable(object : Callable { override fun call() { println("Hello world") } }) + + useCallable(object : Callable { override fun call() { println("Hello world") } },) + + useCallable(object : Callable { override fun call() { println("Hello world") } } + ) + + useCallable(object : Callable { override fun call() { println("Hello world") } }) { + + } + + useCallable( + object : Callable { override fun call() { println("Hello world") } }) + + testtest( + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + ) + + testtest(/* + */foofoo, foofoo, foofoo, /* + + */ + foofoo, bar) + + testtest(foofoo, foofoo, foofoo, foofoo, bar/* + */) + + testtest(foofoo, foofoo, foofoo, foofoo, bar // awdawda + ) + + testtest(foofoo, foofoo, foofoo, foofoo, /* + + */ + bar + ) + + testtest(foofoo // fd + ) + + testtest( /**/ + foofoo + ) + + testtest(foofoo,/**/) + + testtest(foofoo, foofoo, foofoo, foofoo/* + */ , /* */ bar + ) + + testtest(foofoo // fd + ) + + testtest( /**/ + foofoo + ) + + testtest(foofoo,/**/) + + testtest(foofoo, fososos,/* + */ testtest(testtest(foofoo)),) + + testtest(foofoo, testtest(testtest(foofoo,)), /**/testsa) + + testtest(foofoo, testtest(testtest(foofoo,))/* */ , /**/testsa) + + testtest(foofoo, testtest(testtest(foofoo,))/* + */ ,testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), /**/testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), /* + */testsa) + + useCallable("B", "C", Callable { + println("Hello world") + }, /* */ Callable { + println("Hello world") + }) + + useCallable(Callable { println("Hello world") } // ffd + ) + + useCallable(object : Callable { override fun call() { println("Hello world") } + },) + + useCallable(foo() { println("Hello world") + },) + + useCallable({ + println("Hello world") },) + + useCallable(Callable { println("Hello world") } + ,) + + testtest(foofoo, testtest(testtest( + foofoo,)), testsa) + + testtest(foofoo, fososos, testtest(testtest(foofoo)) + ,) + +} + +fun test() { + baz( + f = fun(it: Int): String = "$it" /*dwdwd + */, + name = "" /* + */, + ) +} diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/CollectionLiteralInAnnotation.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/CollectionLiteralInAnnotation.kt new file mode 100644 index 00000000000..02657111dc4 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/CollectionLiteralInAnnotation.kt @@ -0,0 +1,112 @@ +@Anno([1]) +fun a() = Unit + +@Anno([1,]) +fun a() = Unit + +@Anno([1 + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 ]) +fun a() = Unit + +@Anno([1,2]) +fun a() = Unit + +@Anno([1, 2,]) +fun a() = Unit + +@Anno([1, 2 + ]) +fun a() = Unit + +@Anno([ + 1, 2, ]) +fun a() = Unit + +@Anno([ + 1, 2 ]) +fun a() = Unit + +@Anno([1, 2, 2]) +fun a() = Unit + +@Anno([1, 2, 2,]) +fun a() = Unit + +@Anno(["1" + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 , 2 , 2 ]) +fun a() = Unit + +@Anno([1/* + */]) +fun a() = Unit + +@Anno([1, //dw + ]) +fun a() = Unit + +@Anno([1 // ds + ]) +fun a() = Unit + +@Anno([/* + */ // d + 1/* + */,/* + */ ]) +fun a() = Unit + +@Anno([ + /* + */ 1 ]) +fun a() = Unit + +@Anno([1/* + */,2]) +fun a() = Unit + +@Anno([1, 2/* + */,/* + */]) +fun a() = Unit + +@Anno([/* + */1, 2 + ]) +fun a() = Unit + +@Anno(["1" + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 , 2 /* + */ ]) +fun a() = Unit + +@Component( + modules = [ + AppModule::class, DataModule::class, + DomainModule::class + ], +) +fun b() = Unit \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/DestructionDeclarationsInLambda.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/DestructionDeclarationsInLambda.kt new file mode 100644 index 00000000000..21170b923ee --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/DestructionDeclarationsInLambda.kt @@ -0,0 +1,64 @@ +val x: (Pair, Int) -> Unit = { (x, y,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, + y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { ( + x, + y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { ( + x // adw + ,y,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x /* val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +}*/,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y/**/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y/* +*/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (/**/x /**/ /* +*/, // awdawd + y/* +*/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { + (/**/x /**/ /* +*/, // awdawd + y/* +*/), + z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y,), + z, -> + println(x) +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/Enum.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/Enum.kt new file mode 100644 index 00000000000..207fda00b4b --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/Enum.kt @@ -0,0 +1,38 @@ +enum class Enum1 { + A, B,; +} + +enum class Enum2 { + A, B; +} + +enum class Enum3 { + A, B + ; +} + +enum class Enum4 { + A, B, +} + +enum class Enum5 { + A, B, +} + +enum class Enum6(val a: Int) { + A( + 1 + ), B, +} + +enum class Enum7(val a: Int) { + A( + 1 + ), B,; +} + +enum class Enum8(val a: Int) { + A( + 1 + ), B; +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/IndicesAccess.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/IndicesAccess.kt new file mode 100644 index 00000000000..19e5ab15d5d --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/IndicesAccess.kt @@ -0,0 +1,176 @@ +fun foo() { + testtest[foofoo, foofoo, foofoo, + foofoo, bar] + + testtest[ + foofoo, foofoo, foofoo, foofoo, bar + ] + + testtest[foofoo, foofoo, foofoo, foofoo, bar + ] + + testtest[foofoo, foofoo, foofoo, foofoo, + bar + ] + + testtest[foofoo + ] + + testtest[ + foofoo] + + testtest[ + foofoo + ] + + testtest[foofoo,] + + testtest[foofoo, testtest[testtest[foofoo]]] + + testtest[foofoo, fososos, + testtest[testtest[foofoo]],] + + testtest[foofoo, testtest[testtest[foofoo,]], testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], testsa] + + useCallable["A", Callable { println["Hello world"] }] + + useCallable["B", "C", Callable { + println["Hello world"] + }, Callable { + println["Hello world"] + }] + + useCallable[Callable { println["Hello world"] }] + + useCallable[Callable { println["Hello world"] },] + + useCallable[Callable { + println["Hello world"] },] + + useCallable[Callable { println["Hello world"] } + ] + + useCallable[Callable { println["Hello world"] }]{ + + } + + useCallable[ + Callable { println["Hello world"] }] + + useCallable["A", { println["Hello world"] }] + + useCallable["B", "C", { + println["Hello world"] + }, { + println["Hello world"] + }] + + useCallable[{ println["Hello world"] }] + + useCallable[{ println["Hello world"] },] + + useCallable[{ println["Hello world"] } + ,] + + useCallable[{ println["Hello world"] } + ] + + useCallable[ + { println["Hello world"] }] + + useCallable["A", object : Callable { override fun call() { println["Hello world"] } }] + + useCallable["A", object : Callable { + override fun call() { + println["Hello world"] + } + }] + + useCallable["B", "C", object : Callable { override fun call() { println["Hello world"] } }, foo[0,]] + + useCallable[object : Callable { override fun call() { println["Hello world"] } }] + + useCallable[object : Callable { override fun call() { println["Hello world"] } },] + + useCallable[object : Callable { override fun call() { println["Hello world"] } } + ] + + useCallable[object : Callable { override fun call() { println["Hello world"] } }] { + + } + + useCallable[ + object : Callable { override fun call() { println["Hello world"] } }] + + testtest[ + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + ] + + testtest[/* + */foofoo, foofoo, foofoo, /* + + */ + foofoo, bar] + + testtest[foofoo, foofoo, foofoo, foofoo, bar/* + */] + + testtest[foofoo, foofoo, foofoo, foofoo, bar // awdawda + ] + + testtest[foofoo, foofoo, foofoo, foofoo, /* + + */ + bar + ] + + testtest[foofoo // fd + ] + + testtest[ /**/ + foofoo + ] + + testtest[foofoo,/**/] + + testtest[foofoo, foofoo, foofoo, foofoo/* + */ , /* */ bar + ] + + testtest[foofoo // fd + ] + + testtest[ /**/ + foofoo + ] + + testtest[foofoo,/**/] + + testtest[foofoo, fososos,/* + */ testtest[testtest[foofoo]],] + + testtest[foofoo, testtest[testtest[foofoo,]], /**/testsa] + + testtest[foofoo, testtest[testtest[foofoo,]]/* */ , /**/testsa] + + testtest[foofoo, testtest[testtest[foofoo,]]/* + */ ,testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], /**/testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], /* + */testsa] + + useCallable["B", "C", Callable { + println["Hello world"] + }, /* */ Callable { + println["Hello world"] + }] + + useCallable[Callable { println["Hello world"] } // ffd + ] +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/LambdaParameterList.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/LambdaParameterList.kt new file mode 100644 index 00000000000..6ac3c373f33 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/LambdaParameterList.kt @@ -0,0 +1,190 @@ +val x = { + x: Comparable>, + y: String, +-> + println("1") + } + +val x = {x: Comparable>, y: String-> + println("1") + } + +val x = {x: String, y +: String-> + println("1") + } + +val x = { + x: String, + y: String +-> + println("1") + } + +val x = { + x: String, + y: Comparable>,-> + println("1") + } + +val x = { + x: Comparable>, + y: String + ,-> + println("1") + } + +val x = { + x: String, + y: Comparable>, + z: String, +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String,-> + println("1") + } + +val x = { + x: String, + y: String, + z: String + ,-> + println("1") + } + +val x = { + x: String, +-> + println("1") + } + +val x = { + x: String +-> + println("1") + } + +val x = { + x: String,-> + println("1") + } + +val x = { + x: String + ,-> + println("1") + } + +val x = { + x: String , + y: String, +-> + println("1") + } + +val x = { + x: String, + z: String +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String ,-> + println("1") + } + +val x = { + x: String, + z: String + , -> + println("1") + } + +val x = { + x, y: String, + z: String + , -> + println("1") + } + +val x = { + x: String, y: String, z: String +-> + println("1") + } + +val x = { + z: String, v: Comparable>, + +-> + println("1") + } + +val x = {x: String, + y: Comparable>, +-> + println("1") + } + +val x = { + x: Int +-> + println("1") + } + +val x = { + x: String, y: String + , /* */ z: String +-> + println("1") + } + +val x = { + x: String, y: String + /* */, /* */ z: String +-> + println("1") + }() + +val x = { + x: String, /* + */ y: String, + z: String ,-> + println("1") + } + +val x = { + x: String, y: String , z: String /* + */ + , -> + println("1") + } + +val x = { + x: Comparable>, y: String, + z: String + , -> + println("1") + } + +val x = { + x: String, y: String, z: String +-> + println("1") + } diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/LambdaValueParameters.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/LambdaValueParameters.kt new file mode 100644 index 00000000000..d034a157c85 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/LambdaValueParameters.kt @@ -0,0 +1,83 @@ +fun main() { + val x: ( + y: Comparable>, + z: Iterable> // trailing comma + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + z: Iterable> + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>,) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>, + ) -> Int = { + 10 + } + + val x: (y: Comparable>) -> Int = { + 10 + } + + val x: (y: Comparable>,) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>) -> Int = { + 10 + } + + val x: ( + y: Comparable>, // + z: Iterable> // /**/ + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable> + // wd + ) -> Int = { + 10 + } + + val x: (y: Comparable>/* + */, z: Iterable>, /* // + */) -> Int = { + 10 + } + + val x: (/**/y: Comparable>/**/) -> Int = { + 10 + } + + val x: (y: Comparable>/**/,) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( /* + */y: Comparable>) -> Int = { + 10 + } +} diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/MultiVariableDeclaration.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/MultiVariableDeclaration.kt new file mode 100644 index 00000000000..48b97ed2bf0 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/MultiVariableDeclaration.kt @@ -0,0 +1,99 @@ +fun test() { + val (a, b) = 1 to 2 + + val (a, b) = 1 to + 2 + + val (a, b) = 1 + to + 2 + + + val (a, b,) = 1 to 2 + + val (a,) = + b + + val (a, + ) = + b + + val (a + ) = + b + + val (a,) = b + + val ( + a,) = b + + val (a, b + ) = 1 to 2 + + val (a, + b) = 1 to 2 + + val ( + a, b + ) = 1 to 2 + + val ( + a, b, + ) = 1 to 2 + + val (a, b, c, + d, f + ) = 1 to 2 + + val (a, b, c, + d, f, + ) = 1 to 2 + + val (a, b/**/) = 1 to 2 + + val (a, /**/b/**/) /**/=/**/ 1 to + 2 + + val (a,/**/ b) = 1 + to + 2 + + val (a, b/**/,) = 1 to 2 + + val (a/**/, b/**/,/**/) = 1 to 2 + + val (a/**/,/**/) = + b + + val (a,) = b + + val (a, b/**/ + ) = 1 to 2 + + val (a, b// awd + ) = 1 to 2 + + val (a,/**/ b /**/ // awd + ) = 1 to 2 + + val (a, // ad + /**/b) = 1 to 2 + + val ( + a, b // fe + /**/)/**/ = 1 to 2 + + val ( + a, b, // awd + ) = 1 to 2 + + val (a, b, c, + d, f // awd + /* + */) = 1 to 2 + + val (a, b, c, + d, f // awd + , + ) = 1 to 2 +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/ParameterList.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/ParameterList.kt new file mode 100644 index 00000000000..cb00f14928d --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/ParameterList.kt @@ -0,0 +1,458 @@ +class A1 { + val x: String + val y: String + + constructor( + x: String, + y: String, + ) { + this.x = x + this.y = y + } +} + +class B1 { + val x: String + val y: String + + constructor( + x: String, + y: String + ) { + this.x = x + this.y = y + } +} + +class C1 { + val x: String + val y: String + + constructor( + x: String, + y: String,) { + this.x = x + this.y = y + } +} + +class D1 { + val x: String + val y: String + + constructor( + x: String, + y: String + ,) { + this.x = x + this.y = y + } +} + +class A2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String, + ) { + this.x = x + this.y = y + this.z = z + } +} + +class B2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String + ) { + this.x = x + this.y = y + this.z = z + } +} + +class C2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String,) { + this.x = x + this.y = y + this.z = z + } +} + +class D2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String + ,) { + this.x = x + this.y = y + this.z = z + } +} + +class A3 { + val x: String + + constructor(x: String,) { + this.x = x + } +} + +class B3 { + val x: String + + constructor(x: String) { + this.x = x + } +} + +class C3 { + val x: String + + constructor( + x: String,) { + this.x = x + } +} + +class D3 { + val x: String + + constructor( + x: String + ,) { + this.x = x + } +} + +class E1 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, z: String,) { + this.x = x + this.y = y + this.z = z + } +} + +class E2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, z: String) { + this.x = x + this.y = y + this.z = z + } +} +class A1( + val x: String, + y: String, +) + +class B1( + val x: String, + val y: String +) + +class C1( + val x: String, + val y: String,) + +class D1( + val x: String, + val y: String + ,) + +class A2( + val x: String, + val y: String, + val z: String, +) + +class B2( + val x: String, + val y: String, + val z: String +) + +class C2( + val x: String, + val y: String, + val z: String,) + +class D2( + val x: String, + val y: String, + val z: String + ,) + +class A3( + val x: String, +) + +class B3( + val x: String +) + +class C3( + val x: String,) + +class D3( + val x: String + ,) + +class A4( + val x: String , + val y: String, + val z: String , +) + +class B4( + val x: String, + val y: String, + val z: String +) + +class C4( + val x: String, + val y: String, + val z: String ,) + +class D4( + val x: String, + val y: String, + val z: String + , ) + +class E1( + val x: String, val y: String, + val z: String + , ) + +class E2( + val x: String, val y: String, val z: String +) + +class C( + z: String, val v: Int, val x: Int = + 42, val y: Int = + 42 +) + +val foo1: (Int, Int) -> Int = fun( + x, + y, +): Int = 42 + +val foo2: (Int, Int) -> Int = fun( + x, + y +): Int { + return x + y +} + +val foo3: (Int, Int) -> Int = fun( + x, y, +): Int { + return x + y +} + +val foo4: (Int) -> Int = fun( + x, +): Int = 42 + +val foo5: (Int) -> Int = fun( + x +): Int = 42 + +val foo6: (Int) -> Int = fun(x,): Int = 42 + +val foo7: (Int) -> Int = fun(x): Int = 42 + +val foo8: (Int, Int, Int) -> Int = fun (x, y: Int, z,): Int { + return x + y +} + +val foo9: (Int, Int, Int) -> Int = fun ( + x, + y: Int, + z, +): Int = 42 + +val foo10: (Int, Int, Int) -> Int = fun ( + x, + y: Int, + z: Int +): Int = 43 + +val foo10 = fun ( + x: Int, + y: Int, + z: Int +): Int = 43 + +val foo11 = fun ( + x: Int, + y: Int, + z: Int, +): Int = 43 + +val foo12 = fun ( + x: Int, y: Int, z: Int, +): Int = 43 + +val foo13 = fun (x: Int, y: Int, z: Int, +): Int = 43 + +val foo14 = fun (x: Int, y: Int, z: Int + ,): Int = 43 + +fun a1( + x: String, + y: String, +) = Unit + +fun b1( + x: String, + y: String +) = Unit + +fun c1( + x: String, + y: String,) = Unit + +fun d1( + x: String, + y: String + ,) = Unit + +fun a2( + x: String, + y: String, + z: String, +) = Unit + +fun b2( + x: String, + y: String, + z: String +) = Unit + +fun c2( + x: String, + y: String, + z: String,) = Unit + +fun d2( + x: String, + y: String, + z: String + ,) = Unit + +fun a3( + x: String, +) = Unit + +fun b3( + x: String +) = Unit + +fun c3( + x: String,) = Unit + +fun d3( + x: String + ,) = Unit + +fun a4( + x: String + , + y: String, + z: String , +) = Unit + +fun b4( + x: String, + y: String, + z: String +) = Unit + +fun c4(x: String, + y: String, + z: String ,) = Unit + +fun d4( + x: String, + y: String, + z: String + , ) = Unit + +fun foo( + x: Int = + 42 +) { +} + +class C( + val x: Int = + 42 +) + +class G( + val x: String, val y: String + = "", /* */ val z: String +) + +class G( + val x: String, val y: String + = "" /* */, /* */ val z: String +) + +class H( + val x: String, /* + */ val y: String, + val z: String ,) + +class J( + val x: String, val y: String , val z: String /* + */ + , ) + +class K( + val x: String, val y: String, + val z: String + , ) + +class L( + val x: String, val y: String, val z: String // adwd +) diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/TypeArgumentList.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/TypeArgumentList.kt new file mode 100644 index 00000000000..e46f5c1f3ac --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/TypeArgumentList.kt @@ -0,0 +1,113 @@ +fun foo() { + testtest, + >, + testsa, + >() + + testtest() + + testtest< + foofoo, foofoo, foofoo, foofoo, bar + >() + + testtest() + + testtest() + + testtest() + + testtest< + foofoo>() + + testtest< + foofoo + >() + + testtest() + + testtest>>() + + testtest>,>() + + testtest> + ,>() + + testtest>, testsa>() + + testtest>, testsa>() + + testtest< + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + >() + + testtest() + + testtest() + + testtest() + + testtest() + + testtest() + + testtest< /**/ + foofoo + >() + + testtest() + + testtest() + + testtest() + + testtest< /**/ + foofoo + >() + + testtest() + + testtest() + + testtest< + foofoo,/**/>() + + testtest>,>() + + testtest>, /**/testsa>() + + testtest>/* */ , /**/testsa>() + + testtest>/* + */ ,testsa>() + + testtest>, /**/testsa>() + + testtest>, /* + */testsa>() +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/TypeParameterList.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/TypeParameterList.kt new file mode 100644 index 00000000000..5e01f5ff057 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/TypeParameterList.kt @@ -0,0 +1,261 @@ +class A1< + x: String, + y: String, +> + +class F + +class F2 + +class B1< + x: String, + y: String +> + +class C1< + x: String, + y: String,> + +class D1< + x: String, + y: String + ,> + +class A2< + x: String, + y: String, + z: String, +> + +class B2< + x: String, + y: String, + z: String +> + +class C2< + x: String, + y: String, + z: String,> + +class D2< + x: String, + y: String, + z: String + ,> + +class A3< + x: String, +> + +class B3< + x: String +> + +class C3< + x: String,> + +class D3< + x: String + ,> + +class A4< + x: String , + y: String, + z , +> + +class B4< + x: String, + y, + z: String +> + +class C4< + x: String, + y: String, + z: String ,> + +class D4< + x: String, + y, + z: String + , > + +class E1< + x, y: String, + z: String + , > + +class E2< + x: String, y: String, z: String +> + +class C< + z: String, v + +> + +fun a1() = Unit + +fun b1() = Unit + +fun < + x: String, + y: String,> c1() = Unit + +fun < + x: String, + y: String + ,> d1() = Unit + +fun < + x: String, + y: String, + z: String, +> a2() = Unit + +fun < + x: String, + y: String, + z: String +> b2() = Unit + +fun < + x: String, + y: String, + z: String,> c2() = Unit + +fun < + x: String, + y: String, + z: String + ,> d2() = Unit + +fun < + x: String, +> a3() = Unit + +fun < + x: String +> b3() = Unit + +fun < + x: String,> c3() = Unit + +fun < + x: String + ,> d3() = Unit + +fun < + x: String + , + y: String, + z: String , +> a4() = Unit + +fun < + x: String, + y: String, + z: String +> b4() = Unit + +fun c4() = Unit + +fun < + x: String, + y: String, + z: String + , > d4() = Unit + +fun < + x +> foo() { +} + +fun ag() { + +} + +fun ag() { + +} + +fun < + T> ag() { + +} + +class C< + x: Int +> + +class G< + x: String, y: String + , /* */ z: String +> + +class G< + x: String, y: String + /* */, /* */ z: String +>() + +class H< + x: String, /* + */ y: String, + z: String ,> + +class J< + x: String, y: String , z: String /* + */ + , > + +class K< + x: String, y: String, + z: String + , > + +class L< + x: String, y: String, z: String +> + +class C< + x: Int // adad +> + +class G< + x: String, y: String + , /* */ z: String // adad +> + +class G< + x: String, y: String + /* */, /* */ z: String /**/, +>() + +class H< + x: String, /* + */ y: String, + z: String /* + */ ,> + +class J< + x: String, y: String , z: String /* + */ + , /**/ > + +class K< + x: String, y: String, + z: String // aw + , > + +class L< + x: String, y: String, z: String //awd +> diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/WhenEntry.kt b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/WhenEntry.kt new file mode 100644 index 00000000000..0e9819b8cf6 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/WhenEntry.kt @@ -0,0 +1,75 @@ +fun foo(x: Any) = when (x) { + Comparable::class, Iterable::class, String::class, // trailing comma + -> println(1) + else -> println(3) +} + +fun foo(x: Any) { + when (x) { + Comparable::class, Iterable::class, String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, + String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, + String::class /*// trailing comma*/, -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + 1 -> { + + } + else -> println(3) + } + + when (x) { + 1, -> { + + } + else -> println(3) + } + + when (x) { + 1 + -> { + + } + else -> println(3) + } + + when (x) { + 1, 2, + 3 /**/ -> { + + } + else -> println(3) + } + + when (val c = x) { + 1, 2, + 3 /**/ -> { + + } + else -> println(3) + } + + when { + x in coll + -> { + + } + else -> println(3) + } +} diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/inspectionData/expected.xml b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/inspectionData/expected.xml new file mode 100644 index 00000000000..75f9a4d4e66 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/inspectionData/expected.xml @@ -0,0 +1,740 @@ + + + ArgumentList.kt + 26 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 30 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 32 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 68 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 90 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 116 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 159 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 172 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 177 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 179 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 181 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 184 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 186 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 221 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ArgumentList.kt + 223 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + CollectionLiteralInAnnotation.kt + 4 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 22 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 40 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 70 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + CollectionLiteralInAnnotation.kt + 84 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 1 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 1 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 5 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 22 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 28 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 32 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 36 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 26 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 35 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 47 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 72 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 91 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 95 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 138 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 151 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 156 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 158 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 160 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 163 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 165 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaParameterList.kt + 81 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaParameterList.kt + 175 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + LambdaValueParameters.kt + 20 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaValueParameters.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaValueParameters.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + LambdaValueParameters.kt + 70 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 12 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 14 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 25 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 63 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 65 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 68 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 97 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ParameterList.kt + 118 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 298 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 302 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 449 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeArgumentList.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 38 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 43 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 45 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 78 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 91 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 102 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 104 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 106 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 109 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 111 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeParameterList.kt + 187 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeParameterList.kt + 218 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 240 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 240 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 247 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 252 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 257 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + WhenEntry.kt + 21 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + WhenEntry.kt + 38 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/inspectionData/inspections.test b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/inspectionData/inspections.test new file mode 100644 index 00000000000..8cb7aef617a --- /dev/null +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/inspectionData/inspections.test @@ -0,0 +1,3 @@ +// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.TrailingCommaInspection +// COMPILER_ARGUMENTS: -XXLanguage:-TrailingCommas +// SET_FALSE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/ArgumentList.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/ArgumentList.kt new file mode 100644 index 00000000000..da169db0254 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/ArgumentList.kt @@ -0,0 +1,225 @@ +fun foo() { + testtest(foofoo, foofoo, foofoo, + foofoo, bar) + + testtest( + foofoo, foofoo, foofoo, foofoo, bar + ) + + testtest(foofoo, foofoo, foofoo, foofoo, bar + ) + + testtest(foofoo, foofoo, foofoo, foofoo, + bar + ) + + testtest(foofoo + ) + + testtest( + foofoo) + + testtest( + foofoo + ) + + testtest(foofoo,) + + testtest(foofoo, testtest(testtest(foofoo))) + + testtest(foofoo, fososos, testtest(testtest(foofoo)),) + + testtest(foofoo, testtest(testtest(foofoo,)), testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), testsa) + + useCallable("A", Callable { println("Hello world") }) + + useCallable("B", "C", Callable { + println("Hello world") + }, Callable { + println("Hello world") + }) + + useCallable(Callable { println("Hello world") }) + + useCallable(Callable { println("Hello world") },) + + useCallable(Callable { println("Hello world") } + ) + + useCallable(Callable { println("Hello world") }){ + + } + + useCallable( + Callable { println("Hello world") }) + + useCallable("A", { println("Hello world") }) + + useCallable("B", "C", { + println("Hello world") + }, { + println("Hello world") + }) + + useCallable({ println("Hello world") }) + + useCallable({ println("Hello world") },) + + useCallable({ println("Hello world") } + ) + + useCallable({ println("Hello world") }){ + + } + + useCallable( + { println("Hello world") }) + + useCallable("A", foo() { println("Hello world") }) + + useCallable("B", "C", foo() { + println("Hello world") + }, foo() { + println("Hello world") + }) + + useCallable(foo() { println("Hello world") }) + + useCallable(foo() { println("Hello world") },) + + useCallable(foo() { println("Hello world") } + ) + + useCallable(foo() { println("Hello world") }) { + + } + + useCallable( + foo() { println("Hello world") }) + + useCallable("A", object : Callable { override fun call() { println("Hello world") } }) + + useCallable("A", object : Callable { + override fun call() { + println("Hello world") + } + }) + + useCallable("B", "C", object : Callable { override fun call() { println("Hello world") } }, foo() { + println("Hello world") + }) + + useCallable(object : Callable { override fun call() { println("Hello world") } }) + + useCallable(object : Callable { override fun call() { println("Hello world") } },) + + useCallable(object : Callable { override fun call() { println("Hello world") } } + ) + + useCallable(object : Callable { override fun call() { println("Hello world") } }) { + + } + + useCallable( + object : Callable { override fun call() { println("Hello world") } }) + + testtest( + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + ) + + testtest(/* + */foofoo, foofoo, foofoo, /* + + */ + foofoo, bar) + + testtest(foofoo, foofoo, foofoo, foofoo, bar/* + */) + + testtest(foofoo, foofoo, foofoo, foofoo, bar // awdawda + ) + + testtest(foofoo, foofoo, foofoo, foofoo, /* + + */ + bar + ) + + testtest(foofoo // fd + ) + + testtest( /**/ + foofoo + ) + + testtest(foofoo,/**/) + + testtest(foofoo, foofoo, foofoo, foofoo/* + */ , /* */ bar + ) + + testtest(foofoo // fd + ) + + testtest( /**/ + foofoo + ) + + testtest(foofoo,/**/) + + testtest(foofoo, fososos,/* + */ testtest(testtest(foofoo)),) + + testtest(foofoo, testtest(testtest(foofoo,)), /**/testsa) + + testtest(foofoo, testtest(testtest(foofoo,))/* */ , /**/testsa) + + testtest(foofoo, testtest(testtest(foofoo,))/* + */ ,testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), /**/testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), /* + */testsa) + + useCallable("B", "C", Callable { + println("Hello world") + }, /* */ Callable { + println("Hello world") + }) + + useCallable(Callable { println("Hello world") } // ffd + ) + + useCallable(object : Callable { override fun call() { println("Hello world") } + },) + + useCallable(foo() { println("Hello world") + },) + + useCallable({ + println("Hello world") },) + + useCallable(Callable { println("Hello world") } + ,) + + testtest(foofoo, testtest(testtest( + foofoo,)), testsa) + + testtest(foofoo, fososos, testtest(testtest(foofoo)) + ,) + +} + +fun test() { + baz( + f = fun(it: Int): String = "$it" /*dwdwd + */, + name = "" /* + */, + ) +} diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/CollectionLiteralInAnnotation.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/CollectionLiteralInAnnotation.kt new file mode 100644 index 00000000000..02657111dc4 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/CollectionLiteralInAnnotation.kt @@ -0,0 +1,112 @@ +@Anno([1]) +fun a() = Unit + +@Anno([1,]) +fun a() = Unit + +@Anno([1 + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 ]) +fun a() = Unit + +@Anno([1,2]) +fun a() = Unit + +@Anno([1, 2,]) +fun a() = Unit + +@Anno([1, 2 + ]) +fun a() = Unit + +@Anno([ + 1, 2, ]) +fun a() = Unit + +@Anno([ + 1, 2 ]) +fun a() = Unit + +@Anno([1, 2, 2]) +fun a() = Unit + +@Anno([1, 2, 2,]) +fun a() = Unit + +@Anno(["1" + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 , 2 , 2 ]) +fun a() = Unit + +@Anno([1/* + */]) +fun a() = Unit + +@Anno([1, //dw + ]) +fun a() = Unit + +@Anno([1 // ds + ]) +fun a() = Unit + +@Anno([/* + */ // d + 1/* + */,/* + */ ]) +fun a() = Unit + +@Anno([ + /* + */ 1 ]) +fun a() = Unit + +@Anno([1/* + */,2]) +fun a() = Unit + +@Anno([1, 2/* + */,/* + */]) +fun a() = Unit + +@Anno([/* + */1, 2 + ]) +fun a() = Unit + +@Anno(["1" + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 , 2 /* + */ ]) +fun a() = Unit + +@Component( + modules = [ + AppModule::class, DataModule::class, + DomainModule::class + ], +) +fun b() = Unit \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/DestructionDeclarationsInLambda.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/DestructionDeclarationsInLambda.kt new file mode 100644 index 00000000000..21170b923ee --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/DestructionDeclarationsInLambda.kt @@ -0,0 +1,64 @@ +val x: (Pair, Int) -> Unit = { (x, y,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, + y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { ( + x, + y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { ( + x // adw + ,y,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x /* val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +}*/,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y/**/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y/* +*/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (/**/x /**/ /* +*/, // awdawd + y/* +*/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { + (/**/x /**/ /* +*/, // awdawd + y/* +*/), + z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y,), + z, -> + println(x) +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/Enum.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/Enum.kt new file mode 100644 index 00000000000..207fda00b4b --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/Enum.kt @@ -0,0 +1,38 @@ +enum class Enum1 { + A, B,; +} + +enum class Enum2 { + A, B; +} + +enum class Enum3 { + A, B + ; +} + +enum class Enum4 { + A, B, +} + +enum class Enum5 { + A, B, +} + +enum class Enum6(val a: Int) { + A( + 1 + ), B, +} + +enum class Enum7(val a: Int) { + A( + 1 + ), B,; +} + +enum class Enum8(val a: Int) { + A( + 1 + ), B; +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/IndicesAccess.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/IndicesAccess.kt new file mode 100644 index 00000000000..19e5ab15d5d --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/IndicesAccess.kt @@ -0,0 +1,176 @@ +fun foo() { + testtest[foofoo, foofoo, foofoo, + foofoo, bar] + + testtest[ + foofoo, foofoo, foofoo, foofoo, bar + ] + + testtest[foofoo, foofoo, foofoo, foofoo, bar + ] + + testtest[foofoo, foofoo, foofoo, foofoo, + bar + ] + + testtest[foofoo + ] + + testtest[ + foofoo] + + testtest[ + foofoo + ] + + testtest[foofoo,] + + testtest[foofoo, testtest[testtest[foofoo]]] + + testtest[foofoo, fososos, + testtest[testtest[foofoo]],] + + testtest[foofoo, testtest[testtest[foofoo,]], testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], testsa] + + useCallable["A", Callable { println["Hello world"] }] + + useCallable["B", "C", Callable { + println["Hello world"] + }, Callable { + println["Hello world"] + }] + + useCallable[Callable { println["Hello world"] }] + + useCallable[Callable { println["Hello world"] },] + + useCallable[Callable { + println["Hello world"] },] + + useCallable[Callable { println["Hello world"] } + ] + + useCallable[Callable { println["Hello world"] }]{ + + } + + useCallable[ + Callable { println["Hello world"] }] + + useCallable["A", { println["Hello world"] }] + + useCallable["B", "C", { + println["Hello world"] + }, { + println["Hello world"] + }] + + useCallable[{ println["Hello world"] }] + + useCallable[{ println["Hello world"] },] + + useCallable[{ println["Hello world"] } + ,] + + useCallable[{ println["Hello world"] } + ] + + useCallable[ + { println["Hello world"] }] + + useCallable["A", object : Callable { override fun call() { println["Hello world"] } }] + + useCallable["A", object : Callable { + override fun call() { + println["Hello world"] + } + }] + + useCallable["B", "C", object : Callable { override fun call() { println["Hello world"] } }, foo[0,]] + + useCallable[object : Callable { override fun call() { println["Hello world"] } }] + + useCallable[object : Callable { override fun call() { println["Hello world"] } },] + + useCallable[object : Callable { override fun call() { println["Hello world"] } } + ] + + useCallable[object : Callable { override fun call() { println["Hello world"] } }] { + + } + + useCallable[ + object : Callable { override fun call() { println["Hello world"] } }] + + testtest[ + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + ] + + testtest[/* + */foofoo, foofoo, foofoo, /* + + */ + foofoo, bar] + + testtest[foofoo, foofoo, foofoo, foofoo, bar/* + */] + + testtest[foofoo, foofoo, foofoo, foofoo, bar // awdawda + ] + + testtest[foofoo, foofoo, foofoo, foofoo, /* + + */ + bar + ] + + testtest[foofoo // fd + ] + + testtest[ /**/ + foofoo + ] + + testtest[foofoo,/**/] + + testtest[foofoo, foofoo, foofoo, foofoo/* + */ , /* */ bar + ] + + testtest[foofoo // fd + ] + + testtest[ /**/ + foofoo + ] + + testtest[foofoo,/**/] + + testtest[foofoo, fososos,/* + */ testtest[testtest[foofoo]],] + + testtest[foofoo, testtest[testtest[foofoo,]], /**/testsa] + + testtest[foofoo, testtest[testtest[foofoo,]]/* */ , /**/testsa] + + testtest[foofoo, testtest[testtest[foofoo,]]/* + */ ,testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], /**/testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], /* + */testsa] + + useCallable["B", "C", Callable { + println["Hello world"] + }, /* */ Callable { + println["Hello world"] + }] + + useCallable[Callable { println["Hello world"] } // ffd + ] +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/LambdaParameterList.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/LambdaParameterList.kt new file mode 100644 index 00000000000..6ac3c373f33 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/LambdaParameterList.kt @@ -0,0 +1,190 @@ +val x = { + x: Comparable>, + y: String, +-> + println("1") + } + +val x = {x: Comparable>, y: String-> + println("1") + } + +val x = {x: String, y +: String-> + println("1") + } + +val x = { + x: String, + y: String +-> + println("1") + } + +val x = { + x: String, + y: Comparable>,-> + println("1") + } + +val x = { + x: Comparable>, + y: String + ,-> + println("1") + } + +val x = { + x: String, + y: Comparable>, + z: String, +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String,-> + println("1") + } + +val x = { + x: String, + y: String, + z: String + ,-> + println("1") + } + +val x = { + x: String, +-> + println("1") + } + +val x = { + x: String +-> + println("1") + } + +val x = { + x: String,-> + println("1") + } + +val x = { + x: String + ,-> + println("1") + } + +val x = { + x: String , + y: String, +-> + println("1") + } + +val x = { + x: String, + z: String +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String ,-> + println("1") + } + +val x = { + x: String, + z: String + , -> + println("1") + } + +val x = { + x, y: String, + z: String + , -> + println("1") + } + +val x = { + x: String, y: String, z: String +-> + println("1") + } + +val x = { + z: String, v: Comparable>, + +-> + println("1") + } + +val x = {x: String, + y: Comparable>, +-> + println("1") + } + +val x = { + x: Int +-> + println("1") + } + +val x = { + x: String, y: String + , /* */ z: String +-> + println("1") + } + +val x = { + x: String, y: String + /* */, /* */ z: String +-> + println("1") + }() + +val x = { + x: String, /* + */ y: String, + z: String ,-> + println("1") + } + +val x = { + x: String, y: String , z: String /* + */ + , -> + println("1") + } + +val x = { + x: Comparable>, y: String, + z: String + , -> + println("1") + } + +val x = { + x: String, y: String, z: String +-> + println("1") + } diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/LambdaValueParameters.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/LambdaValueParameters.kt new file mode 100644 index 00000000000..d034a157c85 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/LambdaValueParameters.kt @@ -0,0 +1,83 @@ +fun main() { + val x: ( + y: Comparable>, + z: Iterable> // trailing comma + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + z: Iterable> + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>,) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>, + ) -> Int = { + 10 + } + + val x: (y: Comparable>) -> Int = { + 10 + } + + val x: (y: Comparable>,) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>) -> Int = { + 10 + } + + val x: ( + y: Comparable>, // + z: Iterable> // /**/ + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable> + // wd + ) -> Int = { + 10 + } + + val x: (y: Comparable>/* + */, z: Iterable>, /* // + */) -> Int = { + 10 + } + + val x: (/**/y: Comparable>/**/) -> Int = { + 10 + } + + val x: (y: Comparable>/**/,) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( /* + */y: Comparable>) -> Int = { + 10 + } +} diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/MultiVariableDeclaration.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/MultiVariableDeclaration.kt new file mode 100644 index 00000000000..48b97ed2bf0 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/MultiVariableDeclaration.kt @@ -0,0 +1,99 @@ +fun test() { + val (a, b) = 1 to 2 + + val (a, b) = 1 to + 2 + + val (a, b) = 1 + to + 2 + + + val (a, b,) = 1 to 2 + + val (a,) = + b + + val (a, + ) = + b + + val (a + ) = + b + + val (a,) = b + + val ( + a,) = b + + val (a, b + ) = 1 to 2 + + val (a, + b) = 1 to 2 + + val ( + a, b + ) = 1 to 2 + + val ( + a, b, + ) = 1 to 2 + + val (a, b, c, + d, f + ) = 1 to 2 + + val (a, b, c, + d, f, + ) = 1 to 2 + + val (a, b/**/) = 1 to 2 + + val (a, /**/b/**/) /**/=/**/ 1 to + 2 + + val (a,/**/ b) = 1 + to + 2 + + val (a, b/**/,) = 1 to 2 + + val (a/**/, b/**/,/**/) = 1 to 2 + + val (a/**/,/**/) = + b + + val (a,) = b + + val (a, b/**/ + ) = 1 to 2 + + val (a, b// awd + ) = 1 to 2 + + val (a,/**/ b /**/ // awd + ) = 1 to 2 + + val (a, // ad + /**/b) = 1 to 2 + + val ( + a, b // fe + /**/)/**/ = 1 to 2 + + val ( + a, b, // awd + ) = 1 to 2 + + val (a, b, c, + d, f // awd + /* + */) = 1 to 2 + + val (a, b, c, + d, f // awd + , + ) = 1 to 2 +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/ParameterList.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/ParameterList.kt new file mode 100644 index 00000000000..cb00f14928d --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/ParameterList.kt @@ -0,0 +1,458 @@ +class A1 { + val x: String + val y: String + + constructor( + x: String, + y: String, + ) { + this.x = x + this.y = y + } +} + +class B1 { + val x: String + val y: String + + constructor( + x: String, + y: String + ) { + this.x = x + this.y = y + } +} + +class C1 { + val x: String + val y: String + + constructor( + x: String, + y: String,) { + this.x = x + this.y = y + } +} + +class D1 { + val x: String + val y: String + + constructor( + x: String, + y: String + ,) { + this.x = x + this.y = y + } +} + +class A2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String, + ) { + this.x = x + this.y = y + this.z = z + } +} + +class B2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String + ) { + this.x = x + this.y = y + this.z = z + } +} + +class C2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String,) { + this.x = x + this.y = y + this.z = z + } +} + +class D2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String + ,) { + this.x = x + this.y = y + this.z = z + } +} + +class A3 { + val x: String + + constructor(x: String,) { + this.x = x + } +} + +class B3 { + val x: String + + constructor(x: String) { + this.x = x + } +} + +class C3 { + val x: String + + constructor( + x: String,) { + this.x = x + } +} + +class D3 { + val x: String + + constructor( + x: String + ,) { + this.x = x + } +} + +class E1 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, z: String,) { + this.x = x + this.y = y + this.z = z + } +} + +class E2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, z: String) { + this.x = x + this.y = y + this.z = z + } +} +class A1( + val x: String, + y: String, +) + +class B1( + val x: String, + val y: String +) + +class C1( + val x: String, + val y: String,) + +class D1( + val x: String, + val y: String + ,) + +class A2( + val x: String, + val y: String, + val z: String, +) + +class B2( + val x: String, + val y: String, + val z: String +) + +class C2( + val x: String, + val y: String, + val z: String,) + +class D2( + val x: String, + val y: String, + val z: String + ,) + +class A3( + val x: String, +) + +class B3( + val x: String +) + +class C3( + val x: String,) + +class D3( + val x: String + ,) + +class A4( + val x: String , + val y: String, + val z: String , +) + +class B4( + val x: String, + val y: String, + val z: String +) + +class C4( + val x: String, + val y: String, + val z: String ,) + +class D4( + val x: String, + val y: String, + val z: String + , ) + +class E1( + val x: String, val y: String, + val z: String + , ) + +class E2( + val x: String, val y: String, val z: String +) + +class C( + z: String, val v: Int, val x: Int = + 42, val y: Int = + 42 +) + +val foo1: (Int, Int) -> Int = fun( + x, + y, +): Int = 42 + +val foo2: (Int, Int) -> Int = fun( + x, + y +): Int { + return x + y +} + +val foo3: (Int, Int) -> Int = fun( + x, y, +): Int { + return x + y +} + +val foo4: (Int) -> Int = fun( + x, +): Int = 42 + +val foo5: (Int) -> Int = fun( + x +): Int = 42 + +val foo6: (Int) -> Int = fun(x,): Int = 42 + +val foo7: (Int) -> Int = fun(x): Int = 42 + +val foo8: (Int, Int, Int) -> Int = fun (x, y: Int, z,): Int { + return x + y +} + +val foo9: (Int, Int, Int) -> Int = fun ( + x, + y: Int, + z, +): Int = 42 + +val foo10: (Int, Int, Int) -> Int = fun ( + x, + y: Int, + z: Int +): Int = 43 + +val foo10 = fun ( + x: Int, + y: Int, + z: Int +): Int = 43 + +val foo11 = fun ( + x: Int, + y: Int, + z: Int, +): Int = 43 + +val foo12 = fun ( + x: Int, y: Int, z: Int, +): Int = 43 + +val foo13 = fun (x: Int, y: Int, z: Int, +): Int = 43 + +val foo14 = fun (x: Int, y: Int, z: Int + ,): Int = 43 + +fun a1( + x: String, + y: String, +) = Unit + +fun b1( + x: String, + y: String +) = Unit + +fun c1( + x: String, + y: String,) = Unit + +fun d1( + x: String, + y: String + ,) = Unit + +fun a2( + x: String, + y: String, + z: String, +) = Unit + +fun b2( + x: String, + y: String, + z: String +) = Unit + +fun c2( + x: String, + y: String, + z: String,) = Unit + +fun d2( + x: String, + y: String, + z: String + ,) = Unit + +fun a3( + x: String, +) = Unit + +fun b3( + x: String +) = Unit + +fun c3( + x: String,) = Unit + +fun d3( + x: String + ,) = Unit + +fun a4( + x: String + , + y: String, + z: String , +) = Unit + +fun b4( + x: String, + y: String, + z: String +) = Unit + +fun c4(x: String, + y: String, + z: String ,) = Unit + +fun d4( + x: String, + y: String, + z: String + , ) = Unit + +fun foo( + x: Int = + 42 +) { +} + +class C( + val x: Int = + 42 +) + +class G( + val x: String, val y: String + = "", /* */ val z: String +) + +class G( + val x: String, val y: String + = "" /* */, /* */ val z: String +) + +class H( + val x: String, /* + */ val y: String, + val z: String ,) + +class J( + val x: String, val y: String , val z: String /* + */ + , ) + +class K( + val x: String, val y: String, + val z: String + , ) + +class L( + val x: String, val y: String, val z: String // adwd +) diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/TypeArgumentList.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/TypeArgumentList.kt new file mode 100644 index 00000000000..e46f5c1f3ac --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/TypeArgumentList.kt @@ -0,0 +1,113 @@ +fun foo() { + testtest, + >, + testsa, + >() + + testtest() + + testtest< + foofoo, foofoo, foofoo, foofoo, bar + >() + + testtest() + + testtest() + + testtest() + + testtest< + foofoo>() + + testtest< + foofoo + >() + + testtest() + + testtest>>() + + testtest>,>() + + testtest> + ,>() + + testtest>, testsa>() + + testtest>, testsa>() + + testtest< + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + >() + + testtest() + + testtest() + + testtest() + + testtest() + + testtest() + + testtest< /**/ + foofoo + >() + + testtest() + + testtest() + + testtest() + + testtest< /**/ + foofoo + >() + + testtest() + + testtest() + + testtest< + foofoo,/**/>() + + testtest>,>() + + testtest>, /**/testsa>() + + testtest>/* */ , /**/testsa>() + + testtest>/* + */ ,testsa>() + + testtest>, /**/testsa>() + + testtest>, /* + */testsa>() +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/TypeParameterList.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/TypeParameterList.kt new file mode 100644 index 00000000000..5e01f5ff057 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/TypeParameterList.kt @@ -0,0 +1,261 @@ +class A1< + x: String, + y: String, +> + +class F + +class F2 + +class B1< + x: String, + y: String +> + +class C1< + x: String, + y: String,> + +class D1< + x: String, + y: String + ,> + +class A2< + x: String, + y: String, + z: String, +> + +class B2< + x: String, + y: String, + z: String +> + +class C2< + x: String, + y: String, + z: String,> + +class D2< + x: String, + y: String, + z: String + ,> + +class A3< + x: String, +> + +class B3< + x: String +> + +class C3< + x: String,> + +class D3< + x: String + ,> + +class A4< + x: String , + y: String, + z , +> + +class B4< + x: String, + y, + z: String +> + +class C4< + x: String, + y: String, + z: String ,> + +class D4< + x: String, + y, + z: String + , > + +class E1< + x, y: String, + z: String + , > + +class E2< + x: String, y: String, z: String +> + +class C< + z: String, v + +> + +fun a1() = Unit + +fun b1() = Unit + +fun < + x: String, + y: String,> c1() = Unit + +fun < + x: String, + y: String + ,> d1() = Unit + +fun < + x: String, + y: String, + z: String, +> a2() = Unit + +fun < + x: String, + y: String, + z: String +> b2() = Unit + +fun < + x: String, + y: String, + z: String,> c2() = Unit + +fun < + x: String, + y: String, + z: String + ,> d2() = Unit + +fun < + x: String, +> a3() = Unit + +fun < + x: String +> b3() = Unit + +fun < + x: String,> c3() = Unit + +fun < + x: String + ,> d3() = Unit + +fun < + x: String + , + y: String, + z: String , +> a4() = Unit + +fun < + x: String, + y: String, + z: String +> b4() = Unit + +fun c4() = Unit + +fun < + x: String, + y: String, + z: String + , > d4() = Unit + +fun < + x +> foo() { +} + +fun ag() { + +} + +fun ag() { + +} + +fun < + T> ag() { + +} + +class C< + x: Int +> + +class G< + x: String, y: String + , /* */ z: String +> + +class G< + x: String, y: String + /* */, /* */ z: String +>() + +class H< + x: String, /* + */ y: String, + z: String ,> + +class J< + x: String, y: String , z: String /* + */ + , > + +class K< + x: String, y: String, + z: String + , > + +class L< + x: String, y: String, z: String +> + +class C< + x: Int // adad +> + +class G< + x: String, y: String + , /* */ z: String // adad +> + +class G< + x: String, y: String + /* */, /* */ z: String /**/, +>() + +class H< + x: String, /* + */ y: String, + z: String /* + */ ,> + +class J< + x: String, y: String , z: String /* + */ + , /**/ > + +class K< + x: String, y: String, + z: String // aw + , > + +class L< + x: String, y: String, z: String //awd +> diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/WhenEntry.kt b/idea/testData/inspections/trailingCommaOnWithCodeStyle/WhenEntry.kt new file mode 100644 index 00000000000..0e9819b8cf6 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/WhenEntry.kt @@ -0,0 +1,75 @@ +fun foo(x: Any) = when (x) { + Comparable::class, Iterable::class, String::class, // trailing comma + -> println(1) + else -> println(3) +} + +fun foo(x: Any) { + when (x) { + Comparable::class, Iterable::class, String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, + String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, + String::class /*// trailing comma*/, -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + 1 -> { + + } + else -> println(3) + } + + when (x) { + 1, -> { + + } + else -> println(3) + } + + when (x) { + 1 + -> { + + } + else -> println(3) + } + + when (x) { + 1, 2, + 3 /**/ -> { + + } + else -> println(3) + } + + when (val c = x) { + 1, 2, + 3 /**/ -> { + + } + else -> println(3) + } + + when { + x in coll + -> { + + } + else -> println(3) + } +} diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/inspectionData/expected.xml b/idea/testData/inspections/trailingCommaOnWithCodeStyle/inspectionData/expected.xml new file mode 100644 index 00000000000..ee78bfd3c23 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/inspectionData/expected.xml @@ -0,0 +1,2702 @@ + + + ArgumentList.kt + 3 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 6 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 9 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 13 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 16 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 20 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 23 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 26 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 30 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 32 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 42 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 48 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 56 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 64 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 68 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 70 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 78 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 86 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 90 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 92 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 100 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 108 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 112 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 116 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 118 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 126 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 131 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ArgumentList.kt + 131 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 138 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 140 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 143 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 149 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 152 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 156 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 159 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 162 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ArgumentList.kt + 162 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 165 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 169 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 172 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 177 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 179 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 181 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 182 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ArgumentList.kt + 182 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 184 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 186 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 187 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 193 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 195 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 211 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 211 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ArgumentList.kt + 221 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ArgumentList.kt + 223 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + CollectionLiteralInAnnotation.kt + 4 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 7 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 8 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 12 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 16 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 16 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 22 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 25 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 26 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 30 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 40 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 43 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 44 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 48 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 52 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 52 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 55 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 56 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 60 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 63 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 64 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 70 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + CollectionLiteralInAnnotation.kt + 71 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 76 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 76 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 80 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + CollectionLiteralInAnnotation.kt + 80 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 80 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 84 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + CollectionLiteralInAnnotation.kt + 85 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 89 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 90 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 93 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 94 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 98 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 102 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 103 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + CollectionLiteralInAnnotation.kt + 109 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + DestructionDeclarationsInLambda.kt + 1 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 1 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 5 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 10 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + DestructionDeclarationsInLambda.kt + 16 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + DestructionDeclarationsInLambda.kt + 22 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 28 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 32 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 36 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 40 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + DestructionDeclarationsInLambda.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 47 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + DestructionDeclarationsInLambda.kt + 54 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 55 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + DestructionDeclarationsInLambda.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + Enum.kt + 24 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + Enum.kt + 30 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + Enum.kt + 36 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 3 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 6 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 9 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 13 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 16 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 20 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 23 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 26 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 35 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 43 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 47 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 52 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 60 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 68 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 72 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 77 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 81 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 89 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 91 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 95 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 97 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 105 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 110 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + IndicesAccess.kt + 110 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 117 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 119 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 122 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 128 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 131 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 135 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 138 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 141 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + IndicesAccess.kt + 141 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 144 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 148 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 151 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 156 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 158 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 160 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 161 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + IndicesAccess.kt + 161 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 163 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 165 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 166 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 172 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + IndicesAccess.kt + 174 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaParameterList.kt + 13 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaParameterList.kt + 19 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaParameterList.kt + 48 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaParameterList.kt + 75 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaParameterList.kt + 81 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaParameterList.kt + 100 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaParameterList.kt + 127 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaParameterList.kt + 146 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaParameterList.kt + 153 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaParameterList.kt + 160 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + LambdaParameterList.kt + 160 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaParameterList.kt + 175 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + LambdaParameterList.kt + 187 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaValueParameters.kt + 4 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaValueParameters.kt + 11 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaValueParameters.kt + 20 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaValueParameters.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaValueParameters.kt + 37 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaValueParameters.kt + 43 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaValueParameters.kt + 49 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaValueParameters.kt + 54 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaValueParameters.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + LambdaValueParameters.kt + 70 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaValueParameters.kt + 74 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + LambdaValueParameters.kt + 80 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 12 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 14 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 21 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 25 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 30 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 37 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 45 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 63 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 65 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 68 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 70 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 73 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 76 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 80 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 83 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 91 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + MultiVariableDeclaration.kt + 97 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ParameterList.kt + 20 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 76 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 118 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 171 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 184 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 205 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 224 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 243 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 263 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 269 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 279 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 295 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 298 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 302 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 315 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 321 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 347 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 368 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 387 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 407 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 422 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 428 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 433 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 438 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ParameterList.kt + 438 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + ParameterList.kt + 449 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ParameterList.kt + 457 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 11 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 14 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 17 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 21 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 24 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 28 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 31 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 38 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 43 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 45 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 50 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeArgumentList.kt + 50 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 57 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 59 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 62 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 68 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 71 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 75 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 78 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 81 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeArgumentList.kt + 81 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 84 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 88 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 91 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 102 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 104 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 106 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 107 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeArgumentList.kt + 107 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeArgumentList.kt + 109 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 111 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 112 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 9 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 13 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 53 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 72 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 92 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 96 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 105 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 126 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 145 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 165 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 179 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 187 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeParameterList.kt + 192 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 197 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 202 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 207 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 207 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 218 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 226 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 230 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 235 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + TypeParameterList.kt + 240 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 240 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 247 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 252 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 257 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 260 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + WhenEntry.kt + 15 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + WhenEntry.kt + 21 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + WhenEntry.kt + 38 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + WhenEntry.kt + 45 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + WhenEntry.kt + 54 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + WhenEntry.kt + 62 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + + WhenEntry.kt + 69 + testProject + light_idea_test_case + + Trailing comma recommendations + Missing trailing comma + + \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/inspectionData/inspections.test b/idea/testData/inspections/trailingCommaOnWithCodeStyle/inspectionData/inspections.test new file mode 100644 index 00000000000..05348a5508f --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/inspectionData/inspections.test @@ -0,0 +1,3 @@ +// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.TrailingCommaInspection +// COMPILER_ARGUMENTS: -XXLanguage:+TrailingCommas +// SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/ArgumentList.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/ArgumentList.kt new file mode 100644 index 00000000000..da169db0254 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/ArgumentList.kt @@ -0,0 +1,225 @@ +fun foo() { + testtest(foofoo, foofoo, foofoo, + foofoo, bar) + + testtest( + foofoo, foofoo, foofoo, foofoo, bar + ) + + testtest(foofoo, foofoo, foofoo, foofoo, bar + ) + + testtest(foofoo, foofoo, foofoo, foofoo, + bar + ) + + testtest(foofoo + ) + + testtest( + foofoo) + + testtest( + foofoo + ) + + testtest(foofoo,) + + testtest(foofoo, testtest(testtest(foofoo))) + + testtest(foofoo, fososos, testtest(testtest(foofoo)),) + + testtest(foofoo, testtest(testtest(foofoo,)), testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), testsa) + + useCallable("A", Callable { println("Hello world") }) + + useCallable("B", "C", Callable { + println("Hello world") + }, Callable { + println("Hello world") + }) + + useCallable(Callable { println("Hello world") }) + + useCallable(Callable { println("Hello world") },) + + useCallable(Callable { println("Hello world") } + ) + + useCallable(Callable { println("Hello world") }){ + + } + + useCallable( + Callable { println("Hello world") }) + + useCallable("A", { println("Hello world") }) + + useCallable("B", "C", { + println("Hello world") + }, { + println("Hello world") + }) + + useCallable({ println("Hello world") }) + + useCallable({ println("Hello world") },) + + useCallable({ println("Hello world") } + ) + + useCallable({ println("Hello world") }){ + + } + + useCallable( + { println("Hello world") }) + + useCallable("A", foo() { println("Hello world") }) + + useCallable("B", "C", foo() { + println("Hello world") + }, foo() { + println("Hello world") + }) + + useCallable(foo() { println("Hello world") }) + + useCallable(foo() { println("Hello world") },) + + useCallable(foo() { println("Hello world") } + ) + + useCallable(foo() { println("Hello world") }) { + + } + + useCallable( + foo() { println("Hello world") }) + + useCallable("A", object : Callable { override fun call() { println("Hello world") } }) + + useCallable("A", object : Callable { + override fun call() { + println("Hello world") + } + }) + + useCallable("B", "C", object : Callable { override fun call() { println("Hello world") } }, foo() { + println("Hello world") + }) + + useCallable(object : Callable { override fun call() { println("Hello world") } }) + + useCallable(object : Callable { override fun call() { println("Hello world") } },) + + useCallable(object : Callable { override fun call() { println("Hello world") } } + ) + + useCallable(object : Callable { override fun call() { println("Hello world") } }) { + + } + + useCallable( + object : Callable { override fun call() { println("Hello world") } }) + + testtest( + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + ) + + testtest(/* + */foofoo, foofoo, foofoo, /* + + */ + foofoo, bar) + + testtest(foofoo, foofoo, foofoo, foofoo, bar/* + */) + + testtest(foofoo, foofoo, foofoo, foofoo, bar // awdawda + ) + + testtest(foofoo, foofoo, foofoo, foofoo, /* + + */ + bar + ) + + testtest(foofoo // fd + ) + + testtest( /**/ + foofoo + ) + + testtest(foofoo,/**/) + + testtest(foofoo, foofoo, foofoo, foofoo/* + */ , /* */ bar + ) + + testtest(foofoo // fd + ) + + testtest( /**/ + foofoo + ) + + testtest(foofoo,/**/) + + testtest(foofoo, fososos,/* + */ testtest(testtest(foofoo)),) + + testtest(foofoo, testtest(testtest(foofoo,)), /**/testsa) + + testtest(foofoo, testtest(testtest(foofoo,))/* */ , /**/testsa) + + testtest(foofoo, testtest(testtest(foofoo,))/* + */ ,testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), /**/testsa) + + testtest(foofoo, seee, testtest(testtest(foofoo,)), /* + */testsa) + + useCallable("B", "C", Callable { + println("Hello world") + }, /* */ Callable { + println("Hello world") + }) + + useCallable(Callable { println("Hello world") } // ffd + ) + + useCallable(object : Callable { override fun call() { println("Hello world") } + },) + + useCallable(foo() { println("Hello world") + },) + + useCallable({ + println("Hello world") },) + + useCallable(Callable { println("Hello world") } + ,) + + testtest(foofoo, testtest(testtest( + foofoo,)), testsa) + + testtest(foofoo, fososos, testtest(testtest(foofoo)) + ,) + +} + +fun test() { + baz( + f = fun(it: Int): String = "$it" /*dwdwd + */, + name = "" /* + */, + ) +} diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/CollectionLiteralInAnnotation.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/CollectionLiteralInAnnotation.kt new file mode 100644 index 00000000000..02657111dc4 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/CollectionLiteralInAnnotation.kt @@ -0,0 +1,112 @@ +@Anno([1]) +fun a() = Unit + +@Anno([1,]) +fun a() = Unit + +@Anno([1 + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 ]) +fun a() = Unit + +@Anno([1,2]) +fun a() = Unit + +@Anno([1, 2,]) +fun a() = Unit + +@Anno([1, 2 + ]) +fun a() = Unit + +@Anno([ + 1, 2, ]) +fun a() = Unit + +@Anno([ + 1, 2 ]) +fun a() = Unit + +@Anno([1, 2, 2]) +fun a() = Unit + +@Anno([1, 2, 2,]) +fun a() = Unit + +@Anno(["1" + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 , 2 , 2 ]) +fun a() = Unit + +@Anno([1/* + */]) +fun a() = Unit + +@Anno([1, //dw + ]) +fun a() = Unit + +@Anno([1 // ds + ]) +fun a() = Unit + +@Anno([/* + */ // d + 1/* + */,/* + */ ]) +fun a() = Unit + +@Anno([ + /* + */ 1 ]) +fun a() = Unit + +@Anno([1/* + */,2]) +fun a() = Unit + +@Anno([1, 2/* + */,/* + */]) +fun a() = Unit + +@Anno([/* + */1, 2 + ]) +fun a() = Unit + +@Anno(["1" + ]) +fun a() = Unit + +@Anno([ + 1, ]) +fun a() = Unit + +@Anno([ + 1 , 2 /* + */ ]) +fun a() = Unit + +@Component( + modules = [ + AppModule::class, DataModule::class, + DomainModule::class + ], +) +fun b() = Unit \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/DestructionDeclarationsInLambda.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/DestructionDeclarationsInLambda.kt new file mode 100644 index 00000000000..21170b923ee --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/DestructionDeclarationsInLambda.kt @@ -0,0 +1,64 @@ +val x: (Pair, Int) -> Unit = { (x, y,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, + y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { ( + x, + y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { ( + x // adw + ,y,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x /* val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +}*/,), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y/**/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y/* +*/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (/**/x /**/ /* +*/, // awdawd + y/* +*/), z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { + (/**/x /**/ /* +*/, // awdawd + y/* +*/), + z, -> + println(x) +} + +val x: (Pair, Int) -> Unit = { (x, y,), + z, -> + println(x) +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/Enum.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/Enum.kt new file mode 100644 index 00000000000..207fda00b4b --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/Enum.kt @@ -0,0 +1,38 @@ +enum class Enum1 { + A, B,; +} + +enum class Enum2 { + A, B; +} + +enum class Enum3 { + A, B + ; +} + +enum class Enum4 { + A, B, +} + +enum class Enum5 { + A, B, +} + +enum class Enum6(val a: Int) { + A( + 1 + ), B, +} + +enum class Enum7(val a: Int) { + A( + 1 + ), B,; +} + +enum class Enum8(val a: Int) { + A( + 1 + ), B; +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/IndicesAccess.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/IndicesAccess.kt new file mode 100644 index 00000000000..19e5ab15d5d --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/IndicesAccess.kt @@ -0,0 +1,176 @@ +fun foo() { + testtest[foofoo, foofoo, foofoo, + foofoo, bar] + + testtest[ + foofoo, foofoo, foofoo, foofoo, bar + ] + + testtest[foofoo, foofoo, foofoo, foofoo, bar + ] + + testtest[foofoo, foofoo, foofoo, foofoo, + bar + ] + + testtest[foofoo + ] + + testtest[ + foofoo] + + testtest[ + foofoo + ] + + testtest[foofoo,] + + testtest[foofoo, testtest[testtest[foofoo]]] + + testtest[foofoo, fososos, + testtest[testtest[foofoo]],] + + testtest[foofoo, testtest[testtest[foofoo,]], testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], testsa] + + useCallable["A", Callable { println["Hello world"] }] + + useCallable["B", "C", Callable { + println["Hello world"] + }, Callable { + println["Hello world"] + }] + + useCallable[Callable { println["Hello world"] }] + + useCallable[Callable { println["Hello world"] },] + + useCallable[Callable { + println["Hello world"] },] + + useCallable[Callable { println["Hello world"] } + ] + + useCallable[Callable { println["Hello world"] }]{ + + } + + useCallable[ + Callable { println["Hello world"] }] + + useCallable["A", { println["Hello world"] }] + + useCallable["B", "C", { + println["Hello world"] + }, { + println["Hello world"] + }] + + useCallable[{ println["Hello world"] }] + + useCallable[{ println["Hello world"] },] + + useCallable[{ println["Hello world"] } + ,] + + useCallable[{ println["Hello world"] } + ] + + useCallable[ + { println["Hello world"] }] + + useCallable["A", object : Callable { override fun call() { println["Hello world"] } }] + + useCallable["A", object : Callable { + override fun call() { + println["Hello world"] + } + }] + + useCallable["B", "C", object : Callable { override fun call() { println["Hello world"] } }, foo[0,]] + + useCallable[object : Callable { override fun call() { println["Hello world"] } }] + + useCallable[object : Callable { override fun call() { println["Hello world"] } },] + + useCallable[object : Callable { override fun call() { println["Hello world"] } } + ] + + useCallable[object : Callable { override fun call() { println["Hello world"] } }] { + + } + + useCallable[ + object : Callable { override fun call() { println["Hello world"] } }] + + testtest[ + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + ] + + testtest[/* + */foofoo, foofoo, foofoo, /* + + */ + foofoo, bar] + + testtest[foofoo, foofoo, foofoo, foofoo, bar/* + */] + + testtest[foofoo, foofoo, foofoo, foofoo, bar // awdawda + ] + + testtest[foofoo, foofoo, foofoo, foofoo, /* + + */ + bar + ] + + testtest[foofoo // fd + ] + + testtest[ /**/ + foofoo + ] + + testtest[foofoo,/**/] + + testtest[foofoo, foofoo, foofoo, foofoo/* + */ , /* */ bar + ] + + testtest[foofoo // fd + ] + + testtest[ /**/ + foofoo + ] + + testtest[foofoo,/**/] + + testtest[foofoo, fososos,/* + */ testtest[testtest[foofoo]],] + + testtest[foofoo, testtest[testtest[foofoo,]], /**/testsa] + + testtest[foofoo, testtest[testtest[foofoo,]]/* */ , /**/testsa] + + testtest[foofoo, testtest[testtest[foofoo,]]/* + */ ,testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], /**/testsa] + + testtest[foofoo, seee, testtest[testtest[foofoo,]], /* + */testsa] + + useCallable["B", "C", Callable { + println["Hello world"] + }, /* */ Callable { + println["Hello world"] + }] + + useCallable[Callable { println["Hello world"] } // ffd + ] +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/LambdaParameterList.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/LambdaParameterList.kt new file mode 100644 index 00000000000..6ac3c373f33 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/LambdaParameterList.kt @@ -0,0 +1,190 @@ +val x = { + x: Comparable>, + y: String, +-> + println("1") + } + +val x = {x: Comparable>, y: String-> + println("1") + } + +val x = {x: String, y +: String-> + println("1") + } + +val x = { + x: String, + y: String +-> + println("1") + } + +val x = { + x: String, + y: Comparable>,-> + println("1") + } + +val x = { + x: Comparable>, + y: String + ,-> + println("1") + } + +val x = { + x: String, + y: Comparable>, + z: String, +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String,-> + println("1") + } + +val x = { + x: String, + y: String, + z: String + ,-> + println("1") + } + +val x = { + x: String, +-> + println("1") + } + +val x = { + x: String +-> + println("1") + } + +val x = { + x: String,-> + println("1") + } + +val x = { + x: String + ,-> + println("1") + } + +val x = { + x: String , + y: String, +-> + println("1") + } + +val x = { + x: String, + z: String +-> + println("1") + } + +val x = { + x: String, + y: String, + z: String ,-> + println("1") + } + +val x = { + x: String, + z: String + , -> + println("1") + } + +val x = { + x, y: String, + z: String + , -> + println("1") + } + +val x = { + x: String, y: String, z: String +-> + println("1") + } + +val x = { + z: String, v: Comparable>, + +-> + println("1") + } + +val x = {x: String, + y: Comparable>, +-> + println("1") + } + +val x = { + x: Int +-> + println("1") + } + +val x = { + x: String, y: String + , /* */ z: String +-> + println("1") + } + +val x = { + x: String, y: String + /* */, /* */ z: String +-> + println("1") + }() + +val x = { + x: String, /* + */ y: String, + z: String ,-> + println("1") + } + +val x = { + x: String, y: String , z: String /* + */ + , -> + println("1") + } + +val x = { + x: Comparable>, y: String, + z: String + , -> + println("1") + } + +val x = { + x: String, y: String, z: String +-> + println("1") + } diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/LambdaValueParameters.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/LambdaValueParameters.kt new file mode 100644 index 00000000000..d034a157c85 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/LambdaValueParameters.kt @@ -0,0 +1,83 @@ +fun main() { + val x: ( + y: Comparable>, + z: Iterable> // trailing comma + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + z: Iterable> + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>,) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>, + ) -> Int = { + 10 + } + + val x: (y: Comparable>) -> Int = { + 10 + } + + val x: (y: Comparable>,) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>) -> Int = { + 10 + } + + val x: ( + y: Comparable>, // + z: Iterable> // /**/ + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable> + // wd + ) -> Int = { + 10 + } + + val x: (y: Comparable>/* + */, z: Iterable>, /* // + */) -> Int = { + 10 + } + + val x: (/**/y: Comparable>/**/) -> Int = { + 10 + } + + val x: (y: Comparable>/**/,) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( /* + */y: Comparable>) -> Int = { + 10 + } +} diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/MultiVariableDeclaration.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/MultiVariableDeclaration.kt new file mode 100644 index 00000000000..48b97ed2bf0 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/MultiVariableDeclaration.kt @@ -0,0 +1,99 @@ +fun test() { + val (a, b) = 1 to 2 + + val (a, b) = 1 to + 2 + + val (a, b) = 1 + to + 2 + + + val (a, b,) = 1 to 2 + + val (a,) = + b + + val (a, + ) = + b + + val (a + ) = + b + + val (a,) = b + + val ( + a,) = b + + val (a, b + ) = 1 to 2 + + val (a, + b) = 1 to 2 + + val ( + a, b + ) = 1 to 2 + + val ( + a, b, + ) = 1 to 2 + + val (a, b, c, + d, f + ) = 1 to 2 + + val (a, b, c, + d, f, + ) = 1 to 2 + + val (a, b/**/) = 1 to 2 + + val (a, /**/b/**/) /**/=/**/ 1 to + 2 + + val (a,/**/ b) = 1 + to + 2 + + val (a, b/**/,) = 1 to 2 + + val (a/**/, b/**/,/**/) = 1 to 2 + + val (a/**/,/**/) = + b + + val (a,) = b + + val (a, b/**/ + ) = 1 to 2 + + val (a, b// awd + ) = 1 to 2 + + val (a,/**/ b /**/ // awd + ) = 1 to 2 + + val (a, // ad + /**/b) = 1 to 2 + + val ( + a, b // fe + /**/)/**/ = 1 to 2 + + val ( + a, b, // awd + ) = 1 to 2 + + val (a, b, c, + d, f // awd + /* + */) = 1 to 2 + + val (a, b, c, + d, f // awd + , + ) = 1 to 2 +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/ParameterList.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/ParameterList.kt new file mode 100644 index 00000000000..cb00f14928d --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/ParameterList.kt @@ -0,0 +1,458 @@ +class A1 { + val x: String + val y: String + + constructor( + x: String, + y: String, + ) { + this.x = x + this.y = y + } +} + +class B1 { + val x: String + val y: String + + constructor( + x: String, + y: String + ) { + this.x = x + this.y = y + } +} + +class C1 { + val x: String + val y: String + + constructor( + x: String, + y: String,) { + this.x = x + this.y = y + } +} + +class D1 { + val x: String + val y: String + + constructor( + x: String, + y: String + ,) { + this.x = x + this.y = y + } +} + +class A2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String, + ) { + this.x = x + this.y = y + this.z = z + } +} + +class B2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String + ) { + this.x = x + this.y = y + this.z = z + } +} + +class C2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String,) { + this.x = x + this.y = y + this.z = z + } +} + +class D2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, + z: String + ,) { + this.x = x + this.y = y + this.z = z + } +} + +class A3 { + val x: String + + constructor(x: String,) { + this.x = x + } +} + +class B3 { + val x: String + + constructor(x: String) { + this.x = x + } +} + +class C3 { + val x: String + + constructor( + x: String,) { + this.x = x + } +} + +class D3 { + val x: String + + constructor( + x: String + ,) { + this.x = x + } +} + +class E1 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, z: String,) { + this.x = x + this.y = y + this.z = z + } +} + +class E2 { + val x: String + val y: String + val z: String + + constructor( + x: String, + y: String, z: String) { + this.x = x + this.y = y + this.z = z + } +} +class A1( + val x: String, + y: String, +) + +class B1( + val x: String, + val y: String +) + +class C1( + val x: String, + val y: String,) + +class D1( + val x: String, + val y: String + ,) + +class A2( + val x: String, + val y: String, + val z: String, +) + +class B2( + val x: String, + val y: String, + val z: String +) + +class C2( + val x: String, + val y: String, + val z: String,) + +class D2( + val x: String, + val y: String, + val z: String + ,) + +class A3( + val x: String, +) + +class B3( + val x: String +) + +class C3( + val x: String,) + +class D3( + val x: String + ,) + +class A4( + val x: String , + val y: String, + val z: String , +) + +class B4( + val x: String, + val y: String, + val z: String +) + +class C4( + val x: String, + val y: String, + val z: String ,) + +class D4( + val x: String, + val y: String, + val z: String + , ) + +class E1( + val x: String, val y: String, + val z: String + , ) + +class E2( + val x: String, val y: String, val z: String +) + +class C( + z: String, val v: Int, val x: Int = + 42, val y: Int = + 42 +) + +val foo1: (Int, Int) -> Int = fun( + x, + y, +): Int = 42 + +val foo2: (Int, Int) -> Int = fun( + x, + y +): Int { + return x + y +} + +val foo3: (Int, Int) -> Int = fun( + x, y, +): Int { + return x + y +} + +val foo4: (Int) -> Int = fun( + x, +): Int = 42 + +val foo5: (Int) -> Int = fun( + x +): Int = 42 + +val foo6: (Int) -> Int = fun(x,): Int = 42 + +val foo7: (Int) -> Int = fun(x): Int = 42 + +val foo8: (Int, Int, Int) -> Int = fun (x, y: Int, z,): Int { + return x + y +} + +val foo9: (Int, Int, Int) -> Int = fun ( + x, + y: Int, + z, +): Int = 42 + +val foo10: (Int, Int, Int) -> Int = fun ( + x, + y: Int, + z: Int +): Int = 43 + +val foo10 = fun ( + x: Int, + y: Int, + z: Int +): Int = 43 + +val foo11 = fun ( + x: Int, + y: Int, + z: Int, +): Int = 43 + +val foo12 = fun ( + x: Int, y: Int, z: Int, +): Int = 43 + +val foo13 = fun (x: Int, y: Int, z: Int, +): Int = 43 + +val foo14 = fun (x: Int, y: Int, z: Int + ,): Int = 43 + +fun a1( + x: String, + y: String, +) = Unit + +fun b1( + x: String, + y: String +) = Unit + +fun c1( + x: String, + y: String,) = Unit + +fun d1( + x: String, + y: String + ,) = Unit + +fun a2( + x: String, + y: String, + z: String, +) = Unit + +fun b2( + x: String, + y: String, + z: String +) = Unit + +fun c2( + x: String, + y: String, + z: String,) = Unit + +fun d2( + x: String, + y: String, + z: String + ,) = Unit + +fun a3( + x: String, +) = Unit + +fun b3( + x: String +) = Unit + +fun c3( + x: String,) = Unit + +fun d3( + x: String + ,) = Unit + +fun a4( + x: String + , + y: String, + z: String , +) = Unit + +fun b4( + x: String, + y: String, + z: String +) = Unit + +fun c4(x: String, + y: String, + z: String ,) = Unit + +fun d4( + x: String, + y: String, + z: String + , ) = Unit + +fun foo( + x: Int = + 42 +) { +} + +class C( + val x: Int = + 42 +) + +class G( + val x: String, val y: String + = "", /* */ val z: String +) + +class G( + val x: String, val y: String + = "" /* */, /* */ val z: String +) + +class H( + val x: String, /* + */ val y: String, + val z: String ,) + +class J( + val x: String, val y: String , val z: String /* + */ + , ) + +class K( + val x: String, val y: String, + val z: String + , ) + +class L( + val x: String, val y: String, val z: String // adwd +) diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/TypeArgumentList.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/TypeArgumentList.kt new file mode 100644 index 00000000000..e46f5c1f3ac --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/TypeArgumentList.kt @@ -0,0 +1,113 @@ +fun foo() { + testtest, + >, + testsa, + >() + + testtest() + + testtest< + foofoo, foofoo, foofoo, foofoo, bar + >() + + testtest() + + testtest() + + testtest() + + testtest< + foofoo>() + + testtest< + foofoo + >() + + testtest() + + testtest>>() + + testtest>,>() + + testtest> + ,>() + + testtest>, testsa>() + + testtest>, testsa>() + + testtest< + foofoo, foofoo, foofoo, foofoo, + bar /* + */, /* */ foo + >() + + testtest() + + testtest() + + testtest() + + testtest() + + testtest() + + testtest< /**/ + foofoo + >() + + testtest() + + testtest() + + testtest() + + testtest< /**/ + foofoo + >() + + testtest() + + testtest() + + testtest< + foofoo,/**/>() + + testtest>,>() + + testtest>, /**/testsa>() + + testtest>/* */ , /**/testsa>() + + testtest>/* + */ ,testsa>() + + testtest>, /**/testsa>() + + testtest>, /* + */testsa>() +} \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/TypeParameterList.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/TypeParameterList.kt new file mode 100644 index 00000000000..5e01f5ff057 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/TypeParameterList.kt @@ -0,0 +1,261 @@ +class A1< + x: String, + y: String, +> + +class F + +class F2 + +class B1< + x: String, + y: String +> + +class C1< + x: String, + y: String,> + +class D1< + x: String, + y: String + ,> + +class A2< + x: String, + y: String, + z: String, +> + +class B2< + x: String, + y: String, + z: String +> + +class C2< + x: String, + y: String, + z: String,> + +class D2< + x: String, + y: String, + z: String + ,> + +class A3< + x: String, +> + +class B3< + x: String +> + +class C3< + x: String,> + +class D3< + x: String + ,> + +class A4< + x: String , + y: String, + z , +> + +class B4< + x: String, + y, + z: String +> + +class C4< + x: String, + y: String, + z: String ,> + +class D4< + x: String, + y, + z: String + , > + +class E1< + x, y: String, + z: String + , > + +class E2< + x: String, y: String, z: String +> + +class C< + z: String, v + +> + +fun a1() = Unit + +fun b1() = Unit + +fun < + x: String, + y: String,> c1() = Unit + +fun < + x: String, + y: String + ,> d1() = Unit + +fun < + x: String, + y: String, + z: String, +> a2() = Unit + +fun < + x: String, + y: String, + z: String +> b2() = Unit + +fun < + x: String, + y: String, + z: String,> c2() = Unit + +fun < + x: String, + y: String, + z: String + ,> d2() = Unit + +fun < + x: String, +> a3() = Unit + +fun < + x: String +> b3() = Unit + +fun < + x: String,> c3() = Unit + +fun < + x: String + ,> d3() = Unit + +fun < + x: String + , + y: String, + z: String , +> a4() = Unit + +fun < + x: String, + y: String, + z: String +> b4() = Unit + +fun c4() = Unit + +fun < + x: String, + y: String, + z: String + , > d4() = Unit + +fun < + x +> foo() { +} + +fun ag() { + +} + +fun ag() { + +} + +fun < + T> ag() { + +} + +class C< + x: Int +> + +class G< + x: String, y: String + , /* */ z: String +> + +class G< + x: String, y: String + /* */, /* */ z: String +>() + +class H< + x: String, /* + */ y: String, + z: String ,> + +class J< + x: String, y: String , z: String /* + */ + , > + +class K< + x: String, y: String, + z: String + , > + +class L< + x: String, y: String, z: String +> + +class C< + x: Int // adad +> + +class G< + x: String, y: String + , /* */ z: String // adad +> + +class G< + x: String, y: String + /* */, /* */ z: String /**/, +>() + +class H< + x: String, /* + */ y: String, + z: String /* + */ ,> + +class J< + x: String, y: String , z: String /* + */ + , /**/ > + +class K< + x: String, y: String, + z: String // aw + , > + +class L< + x: String, y: String, z: String //awd +> diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/WhenEntry.kt b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/WhenEntry.kt new file mode 100644 index 00000000000..0e9819b8cf6 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/WhenEntry.kt @@ -0,0 +1,75 @@ +fun foo(x: Any) = when (x) { + Comparable::class, Iterable::class, String::class, // trailing comma + -> println(1) + else -> println(3) +} + +fun foo(x: Any) { + when (x) { + Comparable::class, Iterable::class, String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, + String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, + String::class /*// trailing comma*/, -> println(1) + else -> println(3) + } + + when (x) { + Comparable::class, Iterable::class, String::class /*// trailing comma*/ -> println(1) + else -> println(3) + } + + when (x) { + 1 -> { + + } + else -> println(3) + } + + when (x) { + 1, -> { + + } + else -> println(3) + } + + when (x) { + 1 + -> { + + } + else -> println(3) + } + + when (x) { + 1, 2, + 3 /**/ -> { + + } + else -> println(3) + } + + when (val c = x) { + 1, 2, + 3 /**/ -> { + + } + else -> println(3) + } + + when { + x in coll + -> { + + } + else -> println(3) + } +} diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/inspectionData/expected.xml b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/inspectionData/expected.xml new file mode 100644 index 00000000000..75f9a4d4e66 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/inspectionData/expected.xml @@ -0,0 +1,740 @@ + + + ArgumentList.kt + 26 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 30 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 32 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 68 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 90 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 116 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 159 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 172 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 177 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 179 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 181 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 184 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 186 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ArgumentList.kt + 221 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ArgumentList.kt + 223 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + CollectionLiteralInAnnotation.kt + 4 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 22 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 40 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + CollectionLiteralInAnnotation.kt + 70 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + CollectionLiteralInAnnotation.kt + 84 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 1 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 1 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 5 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 22 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 28 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + DestructionDeclarationsInLambda.kt + 32 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 36 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + DestructionDeclarationsInLambda.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 26 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 35 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 47 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 72 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 91 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 95 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 138 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 151 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 156 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 158 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 160 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 163 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + IndicesAccess.kt + 165 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaParameterList.kt + 81 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaParameterList.kt + 175 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + LambdaValueParameters.kt + 20 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaValueParameters.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + LambdaValueParameters.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + LambdaValueParameters.kt + 70 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 12 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 14 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 25 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 63 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 65 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 68 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + MultiVariableDeclaration.kt + 97 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + ParameterList.kt + 118 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 298 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 302 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + ParameterList.kt + 449 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeArgumentList.kt + 34 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 38 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 43 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 45 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 78 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 91 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 102 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 104 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 106 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 109 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeArgumentList.kt + 111 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeParameterList.kt + 187 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + + TypeParameterList.kt + 218 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 240 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 240 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 247 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 252 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + TypeParameterList.kt + 257 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + WhenEntry.kt + 21 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + + + WhenEntry.kt + 38 + testProject + light_idea_test_case + + Trailing comma recommendations + Redundant trailing comma + + \ No newline at end of file diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/inspectionData/inspections.test b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/inspectionData/inspections.test new file mode 100644 index 00000000000..4625bc5ed68 --- /dev/null +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/inspectionData/inspections.test @@ -0,0 +1,3 @@ +// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.TrailingCommaInspection +// COMPILER_ARGUMENTS: -XXLanguage:+TrailingCommas +// SET_FALSE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/inspectionsLocal/trailingComma/.inspection b/idea/testData/inspectionsLocal/trailingComma/.inspection new file mode 100644 index 00000000000..8d9e8517481 --- /dev/null +++ b/idea/testData/inspectionsLocal/trailingComma/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.TrailingCommaInspection \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/trailingComma/addComma.kt b/idea/testData/inspectionsLocal/trailingComma/addComma.kt new file mode 100644 index 00000000000..815c3d64dd7 --- /dev/null +++ b/idea/testData/inspectionsLocal/trailingComma/addComma.kt @@ -0,0 +1,5 @@ +// COMPILER_ARGUMENTS: -XXLanguage:+TrailingCommas +// FIX: Add trailing comma + +fun a(i: Int, + b: Boolean) = Unit \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/trailingComma/addComma.kt.after b/idea/testData/inspectionsLocal/trailingComma/addComma.kt.after new file mode 100644 index 00000000000..88c61d70292 --- /dev/null +++ b/idea/testData/inspectionsLocal/trailingComma/addComma.kt.after @@ -0,0 +1,7 @@ +// COMPILER_ARGUMENTS: -XXLanguage:+TrailingCommas +// FIX: Add trailing comma + +fun a( + i: Int, + b: Boolean, +) = Unit \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition.kt b/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition.kt new file mode 100644 index 00000000000..25d92ae6408 --- /dev/null +++ b/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition.kt @@ -0,0 +1,5 @@ +// COMPILER_ARGUMENTS: -XXLanguage:+TrailingCommas +// FIX: Fix comma position + +fun a(i: Int /* +*/, b: Boolean) = Unit \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition.kt.after b/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition.kt.after new file mode 100644 index 00000000000..cd0b3a1ec65 --- /dev/null +++ b/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition.kt.after @@ -0,0 +1,8 @@ +// COMPILER_ARGUMENTS: -XXLanguage:+TrailingCommas +// FIX: Fix comma position + +fun a( + i: Int, /* +*/ + b: Boolean, +) = Unit \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/trailingComma/removeComma.kt b/idea/testData/inspectionsLocal/trailingComma/removeComma.kt new file mode 100644 index 00000000000..1bcfba0fe46 --- /dev/null +++ b/idea/testData/inspectionsLocal/trailingComma/removeComma.kt @@ -0,0 +1,4 @@ +// COMPILER_ARGUMENTS: -XXLanguage:+TrailingCommas +// FIX: Remove trailing comma + +fun a(i: Int, b: Boolean,) = Unit \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/trailingComma/removeComma.kt.after b/idea/testData/inspectionsLocal/trailingComma/removeComma.kt.after new file mode 100644 index 00000000000..3eff3145a52 --- /dev/null +++ b/idea/testData/inspectionsLocal/trailingComma/removeComma.kt.after @@ -0,0 +1,4 @@ +// COMPILER_ARGUMENTS: -XXLanguage:+TrailingCommas +// FIX: Remove trailing comma + +fun a(i: Int, b: Boolean) = Unit \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractInspectionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractInspectionTest.kt index 49e5e929e34..30f08d3939e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractInspectionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractInspectionTest.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.codeInsight +import com.intellij.application.options.CodeStyle import com.intellij.codeInspection.ex.EntryPointsManagerBase import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.command.CommandProcessor @@ -14,6 +15,7 @@ import com.intellij.psi.PsiFile import com.intellij.testFramework.TestLoggerFactory import org.jdom.Document import org.jdom.input.SAXBuilder +import org.jetbrains.kotlin.formatter.FormatSettingsUtil import org.jetbrains.kotlin.idea.core.script.isScriptChangesNotifierDisabled import org.jetbrains.kotlin.idea.inspections.runInspection import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase @@ -114,7 +116,9 @@ abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTestCase() } }.toList() + val codeStyleSettings = CodeStyle.getSettings(project) try { + FormatSettingsUtil.createConfigurator(options, codeStyleSettings).configureSettings() fixtureClasses.forEach { TestFixtureExtension.loadFixture(it, myFixture.module) } configExtra(psiFiles, options) @@ -141,6 +145,7 @@ abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTestCase() } } finally { + codeStyleSettings.clearCodeStyleSettings() if (configured) { rollbackCompilerOptions(project, module) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java index fdd188d0f9b..8473ab3620c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java @@ -373,6 +373,26 @@ public class InspectionTestGenerated extends AbstractInspectionTest { runTest("idea/testData/inspections/suspiciousEqualsCombination/inspectionData/inspections.test"); } + @TestMetadata("trailingCommaOffWithCodeStyle/inspectionData/inspections.test") + public void testTrailingCommaOffWithCodeStyle_inspectionData_Inspections_test() throws Exception { + runTest("idea/testData/inspections/trailingCommaOffWithCodeStyle/inspectionData/inspections.test"); + } + + @TestMetadata("trailingCommaOffWithoutCodeStyle/inspectionData/inspections.test") + public void testTrailingCommaOffWithoutCodeStyle_inspectionData_Inspections_test() throws Exception { + runTest("idea/testData/inspections/trailingCommaOffWithoutCodeStyle/inspectionData/inspections.test"); + } + + @TestMetadata("trailingCommaOnWithCodeStyle/inspectionData/inspections.test") + public void testTrailingCommaOnWithCodeStyle_inspectionData_Inspections_test() throws Exception { + runTest("idea/testData/inspections/trailingCommaOnWithCodeStyle/inspectionData/inspections.test"); + } + + @TestMetadata("trailingCommaOnWithoutCodeStyle/inspectionData/inspections.test") + public void testTrailingCommaOnWithoutCodeStyle_inspectionData_Inspections_test() throws Exception { + runTest("idea/testData/inspections/trailingCommaOnWithoutCodeStyle/inspectionData/inspections.test"); + } + @TestMetadata("twoSetOfTypeparameters/inspectionData/inspections.test") public void testTwoSetOfTypeparameters_inspectionData_Inspections_test() throws Exception { runTest("idea/testData/inspections/twoSetOfTypeparameters/inspectionData/inspections.test"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index ae56efabdf2..7ded403f2ce 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -12258,6 +12258,34 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { } } + @TestMetadata("idea/testData/inspectionsLocal/trailingComma") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TrailingComma extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("addComma.kt") + public void testAddComma() throws Exception { + runTest("idea/testData/inspectionsLocal/trailingComma/addComma.kt"); + } + + public void testAllFilesPresentInTrailingComma() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/inspectionsLocal/trailingComma"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true); + } + + @TestMetadata("changeCommaPosition.kt") + public void testChangeCommaPosition() throws Exception { + runTest("idea/testData/inspectionsLocal/trailingComma/changeCommaPosition.kt"); + } + + @TestMetadata("removeComma.kt") + public void testRemoveComma() throws Exception { + runTest("idea/testData/inspectionsLocal/trailingComma/removeComma.kt"); + } + } + @TestMetadata("idea/testData/inspectionsLocal/unlabeledReturnInsideLambda") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)