Repository: pinterest/ktlint
Issue: Conflict between requiring space after “,” and no space before “)”

## Expected Behavior
If ktlint makes a suggestion regarding whitespace between "," and ")" which the developer then applies, ktlint should accept the suggestion that it made

If it is disallowed to have a trailing “,” before “)”, could the check say that instead?

## Observed Behavior

We have some code that looks like this:

```
  // Ignore lint warnings in documentation snippets
  @file:Suppress("unused", "UNUSED_PARAMETER", "UNUSED_VARIABLE",)
```

When we run `./gradlew ktlint`, it says:

```
  > Task :compose:integration-tests:docs-snippets:ktlint FAILED
  frameworks/support/compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/interoperability/Interoperability.kt:19:64: Missing spacing after ","
```

When we add a space to make the code look like this:

```
  // Ignore lint warnings in documentation snippets
  @file:Suppress("unused", "UNUSED_PARAMETER", "UNUSED_VARIABLE", )
```

We get this error:

```
  > Task :compose:integration-tests:docs-snippets:ktlint
  frameworks/support/compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/interoperability/Interoperability.kt:19:64: Unexpected spacing before ")"
```

## Steps to Reproduce
The source file: https://android.googlesource.com/platform/frameworks/support/+/e096810f5ad8e55dd5daf6477beaeef233549d55/compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/interoperability/Interoperability.kt
The repository: https://android.googlesource.com/platform/frameworks/support/+/e096810f5ad8e55dd5daf6477beaeef233549d55/README.md

## Your Environment
* Version of ktlint used: 0.39.0
Ktlint config: https://android.googlesource.com/platform/frameworks/support/+/e096810f5ad8e55dd5daf6477beaeef233549d55/buildSrc/src/main/kotlin/androidx/build/Ktlint.kt (except that I'm removing the disabling of paren-spacing and import-ordering as suggested in https://github.com/pinterest/ktlint/issues/967#issuecomment-729029848 ) 

## Workaround

It seems to work to simply delete the trailing ","

Thanks!

Changed files:
ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRule.kt
ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRuleTest.kt

diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRule.kt
index 17485ea7..5278454d 100644
--- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRule.kt
+++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRule.kt
@@ -1,6 +1,7 @@
 package com.pinterest.ktlint.ruleset.standard
 
 import com.pinterest.ktlint.core.Rule
+import com.pinterest.ktlint.core.ast.ElementType.RPAR
 import com.pinterest.ktlint.core.ast.isPartOfString
 import com.pinterest.ktlint.core.ast.isWhiteSpaceWithNewline
 import com.pinterest.ktlint.core.ast.nextLeaf
@@ -41,7 +42,8 @@ class SpacingAroundCommaRule : Rule("comma-spacing") {
                     }
                 }
             }
-            if (node.nextLeaf() !is PsiWhiteSpace) {
+            val nextLeaf = node.nextLeaf()
+            if (nextLeaf !is PsiWhiteSpace && nextLeaf?.elementType != RPAR) {
                 emit(node.startOffset + 1, "Missing spacing after \\"${node.text}\\"", true)
                 if (autoCorrect) {
                     node.upsertWhitespaceAfterMe(" ")
diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRuleTest.kt
index 47c69908..e29022f3 100644
--- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRuleTest.kt
+++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRuleTest.kt
@@ -95,4 +95,15 @@ class SpacingAroundCommaRuleTest {
             """.trimIndent()
         )
     }
+
+    @Test
+    fun testCommaBeforeRightParenthesis() {
+        assertThat(
+            SpacingAroundCommaRule().lint(
+                """
+                @file:Suppress("unused", "UNUSED_PARAMETER", "UNUSED_VARIABLE",)
+                """.trimIndent()
+            )
+        ).isEmpty()
+    }
 }