Eslint: comma-dangle reports incorrect position in array with ternary item

Created on 2 Oct 2016  路  1Comment  路  Source: eslint/eslint

Tell us about your environment

  • ESLint Version: 3.7.0
  • Node Version: 4.2.2
  • npm Version: 3.10.7

What parser (default, Babel-ESLint, etc.) are you using?

[email protected]

Please show your full configuration:

module.exports = {
  "extends": "eslint-config-airbnb",
  "env": {
    "browser": true,
    "node": true,
    "mocha": true
  },
  "parser": "babel-eslint",
  "rules": {
    "no-unused-vars": "warn",
    "no-alert": "warn",
    "no-console": "warn",
    "no-use-before-define": "warn",
    "no-var": "warn",
    "block-scoped-var": "warn",
    "guard-for-in": "off",
    "no-shadow": "off",
    "no-param-reassign": "off",

    "indent": [ "warn", 2, { "SwitchCase": 1 } ],
    "padded-blocks": "off",
    "spaced-comment": "warn",
    "comma-dangle": [ "warn", "always-multiline" ],
    "space-in-parens": "off",
    "curly": [ "off", "all" ],
    "array-bracket-spacing": [ "warn", "always" ],
    "object-curly-spacing": [ "warn", "always" ],
    "computed-property-spacing": "off",
    "brace-style": [ "warn", "stroustrup", { "allowSingleLine": true } ],
    "no-trailing-spaces": [ "warn", { "skipBlankLines": true } ],
    "linebreak-style": [ "warn", "unix" ],
    "no-multiple-empty-lines": [ "warn", { "max": 2, "maxEOF": 1 } ],
    "eol-last": [ "error", "unix" ],
    "id-length": [ "warn", { "min": 2, "exceptions": [ "_", "$", "i", "j", "k", "x", "y", "e" ] } ],
    "camelcase": "warn",
    "func-names": "warn",
    "keyword-spacing": "warn",
    "space-before-blocks": "warn",
    "space-before-function-paren": [ "warn", { "anonymous": "always", "named": "never" } ],
    "quotes": [ "warn", "single", "avoid-escape" ],
    "no-multi-spaces": [ "warn", { "exceptions": { "VariableDeclarator": true, "ImportDeclaration": true } } ],
    "dot-notation": "off",
    "prefer-template": "off",
    "prefer-arrow-callback": "warn",
    "max-len": [ "warn", 250, 4, { "ignoreComments": true } ],
    "arrow-parens": [ "warn", "always" ],
    "arrow-body-style": "off",
    "object-shorthand": "off",
    "no-case-declarations": "warn",
    "no-nested-ternary": "off",
    "global-require": "off",
    "no-underscore-dangle": "off",
    "no-useless-concat": "off",
    "no-mixed-operators": "off",
    "no-bitwise": "off",

    "react/prop-types": "warn",
    "react/forbid-prop-types": "off",
    "react/no-unused-prop-types": "off",
    "react/react-in-jsx-scope": "error",
    "react/jsx-filename-extension": [ "warn", { "extensions": [ ".js", ".jsx" ] } ],
    "react/jsx-uses-react": "error",
    "react/jsx-uses-vars": "error",
    "react/jsx-quotes": "off",
    "react/jsx-closing-bracket-location": "warn",
    "react/jsx-space-before-closing": "warn",
    "react/jsx-curly-spacing": "off",
    "react/jsx-indent": "off",
    "react/self-closing-comp": "warn",
    "react/no-multi-comp": "off",
    "react/sort-comp": "off",
    "react/prefer-stateless-function": "warn",
    "react/no-children-prop": "off",
    "jsx-quotes": "error",
    "jsx-a11y/img-uses-alt": "off",

    "import/default": "off",
    "import/no-duplicates": "off",
    "import/named": "off",
    "import/namespace": "off",
    "import/newline-after-import": "off",
    "import/imports-first": "off",
    "import/no-unresolved": "error",
    "import/no-named-as-default": "error",
    "import/extensions": [ "warn", "always", { "": "never", "js": "never" } ],
  },
  "plugins": [
    "react",
    "import",
  ],
  "settings": {
    "import/ignore": [
      "node_modules",
      "\\.(scss|less|css)$",
    ],
    "import/resolver": {
      "node": {
        "moduleDirectory": [
          "./src",
          "./api",
          "./common",
        ],
      },
      "webpack": {
        "config": "./webpack/configForEslintImportResolver.js",
      },
    },
  },
  "globals": {
    "__SERVER_ENV__": true,
    "__DEVELOPMENT__": true,
    "__SERVER__": true,
    "__SERVER_DEVTOOLS__": true,
    "__SERVER_DISABLE_SERVERSIDE_RENDERING__": true,
    "__CLIENT__": true,
    "__CLIENT_DEVTOOLS__": true,
    "__LOCALHOST__": true,
    "__FAST_DEVELOPMENT__": true,
  },
};

What did you do? Please include the actual source code causing the issue.

Reduced test case:

let xxx; let yyy;
const zzz = [
  (xxx
    ? yyy
    : ''   // <<< reports that the comma is missing here
  )   // <<< should report the missing comma here
];
zzz.toString();  // to prevent unused variable warning in the reduced test case

What did you expect to happen?

Correct positioning of the warning (after the closing paren where the comma-dangle is expected).

What actually happened? Please include the actual, raw output from ESLint.

  5:13  warning  Missing trailing comma  comma-dangle
accepted archived due to age bug rule

Most helpful comment

I was able to reproduce this in the demo. This does seem like a bug -- thanks for the report!

>All comments

I was able to reproduce this in the demo. This does seem like a bug -- thanks for the report!

Was this page helpful?
0 / 5 - 0 ratings