Repository: eslint/eslint (js)

Issue:
`comma-spacing` has conflict with `space-in-parens`
<!--
    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).

    This template is for bug reports. If you are here for another reason, please see below:

    1. To propose a new rule: https://eslint.org/docs/developer-guide/contributing/new-rules
    2. To request a rule change: https://eslint.org/docs/developer-guide/contributing/rule-changes
    3. To request a change that is not a bug fix, rule change, or new rule: https://eslint.org/docs/developer-guide/contributing/changes
    4. If you have any questions, please stop by our chatroom: https://gitter.im/eslint/eslint

    Note that leaving sections blank will make it difficult for us to troubleshoot and we may have to close the issue.
-->

**Tell us about your environment**

* **ESLint Version:** 5.12.1

**What parser (default, Babel-ESLint, etc.) are you using?**
default

**Please show your full configuration:**

<details>
<summary>Configuration</summary>

<!-- Paste your configuration below: -->
```json
{
  "rules": {
    "comma-spacing": 2,
    "space-in-parens": [2, "never"]
  }
}
```

</details>

**What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.**

<!-- Paste the source code below: -->
Source code:
```js
fn(a, b, )

// or

fn(a, b,)
```

Here is the reproduction link: https://eslint.org/demo/#eyJ0ZXh0IjoiLyogZXNsaW50IGNvbW1hLXNwYWNpbmc6IDIgKi9cclxuLyogZXNsaW50IHNwYWNlLWluLXBhcmVuczogWzIsICduZXZlciddICovXHJcbmZuKGEsIGIsKSIsIm9wdGlvbnMiOnsicGFyc2VyT3B0aW9ucyI6eyJlY21hVmVyc2lvbiI6OSwic291cmNlVHlwZSI6InNjcmlwdCIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6e30sImVudiI6e319fQ==

**What did you expect to happen?**
Lint-free.

**What actually happened? Please include the actual, raw output from ESLint.**
Reported linting error, see the reproduction link.

**Are you willing to submit a pull request to fix this bug?**
Yes.

Pull request description:
Fix: ignore comma before closing paren (fixes #11295)
<!--
    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
-->

**What is the purpose of this pull request? (put an "X" next to item)**

[x] Bug fix

<!--
    If the item you've checked above has a template, please paste the template questions below and answer them. (If this pull request is addressing an issue, you can just paste a link to the issue here instead.)
-->

<!--
    Please ensure your pull request is ready:

    - Read the pull request guide (https://eslint.org/docs/developer-guide/contributing/pull-requests)
    - Include tests for this change
    - Update documentation for this change (if appropriate)
-->

<!--
    The following is required for all pull requests:
-->

**What changes did you make? (Give an overview)**
Fixes #11295 

**Is there anything you'd like reviewers to focus on?**
Maybe no.


Patch:
diff --git a/lib/rules/comma-spacing.js b/lib/rules/comma-spacing.js
index 2db0035b5..1d1cf2e59 100644
--- a/lib/rules/comma-spacing.js
+++ b/lib/rules/comma-spacing.js
@@ -118,6 +118,10 @@ module.exports = {
                 report(reportItem, "before", tokens.left);
             }
 
+            if (tokens.right && astUtils.isClosingParenToken(tokens.right)) {
+                return;
+            }
+
             if (tokens.right && !options.after && tokens.right.type === "Line") {
                 return;
             }


Test patch:
diff --git a/tests/lib/rules/comma-spacing.js b/tests/lib/rules/comma-spacing.js
index d5c8ff0ec..2df7c71fa 100644
--- a/tests/lib/rules/comma-spacing.js
+++ b/tests/lib/rules/comma-spacing.js
@@ -61,6 +61,10 @@ ruleTester.run("comma-spacing", rule, {
         "['  ,  ']",
         { code: "[`  ,  `]", parserOptions: { ecmaVersion: 6 } },
         { code: "`${[1, 2]}`", parserOptions: { ecmaVersion: 6 } },
+        { code: "fn(a, b,)", parserOptions: { ecmaVersion: 2018 } }, // #11295
+        { code: "const fn = (a, b,) => {}", parserOptions: { ecmaVersion: 2018 } }, // #11295
+        { code: "const fn = function (a, b,) {}", parserOptions: { ecmaVersion: 2018 } }, // #11295
+        { code: "function fn(a, b,) {}", parserOptions: { ecmaVersion: 2018 } }, // #11295
         "foo(/,/, 'a')",
         "var x = ',,,,,';",
         "var code = 'var foo = 1, bar = 3;'",