question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

comma-style rule fails on parenthesized array item

See original GitHub issue

What version of ESLint are you using? eslint@2.8.0

What parser (default, Babel-ESLint, etc.) are you using? "parser": "babel-eslint",

Please show your full configuration:

{
  "extends": "eslint-config-airbnb",
  "env": {
    "browser": true,
    "node": true,
    "mocha": true
  },
  "parser": "babel-eslint",
  "rules": {
    //
    // Safety
    //
    "no-unused-vars": 1,
    // Do not allow `alert` calls.
    "no-alert": 1,
    // Use the `eslint-disable-line no-console` comment for intentional console statements.
    "no-console": 1,
    // The `no-use-before-define` prevents variable and function use before definition.
    "no-use-before-define": 1,
    // The `no-var` enforces `const` and `let`.
    "no-var": 1,
    // The `block-scoped-var` warns about possibly invalid logic when `var` is declared in a block scope and used outside. We prefer `const` and `let` over `var` but keep this for now.
    "block-scoped-var": 1,
    // Disable `guard-for-in` because we use `Object.keys().forEach` and do not have to extend `Object.prototype` for older browsers.
    "guard-for-in": 0,
    // Disable `no-shadow` and `no-param-reassign` to avoid useless renaming. Be careful.
    "no-shadow": 0,
    "no-param-reassign": 0,

    //
    // Coding style
    //
    "indent": [ 1, 2, { "SwitchCase": 1 } ],
    "padded-blocks": 0,
    // The `spaced-comment` warns about the commented-out source code and dirty comments.
    "spaced-comment": 1,
    // The `comma-dangle` helps to keep version control clean if array or object items are added or removed - only the lines that are actually changed will be highlighted.
    "comma-dangle": 0,
    "space-in-parens": 0,
    // TODO(sompylasar): Re-enable `curly` and fix.
    "curly": [ 0, "all" ],
    "array-bracket-spacing": [ 1, "always" ],
    "object-curly-spacing": [ 1, "always" ],
    "computed-property-spacing": 0,
    "brace-style": [ 1, "stroustrup", { "allowSingleLine": true } ],
    "no-trailing-spaces": [ 1, { "skipBlankLines": true } ],
    "linebreak-style": [ 1, "unix" ],
    "no-multiple-empty-lines": [ 1, { "max": 3, "maxEOF": 1 } ],
    "eol-last": [ 2, "unix" ],
    "id-length": [ 1, { "min": 2, "exceptions": [ "_", "$", "i", "j", "k", "x", "y", "e" ] } ],
    "camelcase": 1,
    "func-names": 1,
    "keyword-spacing": 1,
    "space-before-blocks": 1,
    "space-before-function-paren": [ 1, { "anonymous": "always", "named": "never" } ],
    "quotes": [ 1, "single", "avoid-escape" ],
    "no-multi-spaces": [ 1, { "exceptions": { "VariableDeclarator": true, "ImportDeclaration": true } } ],
    "dot-notation": 0,
    "prefer-template": 0,
    "max-len": [ 1, 250, 4, { "ignoreComments": true } ],
    "arrow-body-style": 0,
    "object-shorthand": 0,
    "no-case-declarations": 1,

    //
    // React:
    //
    "react/prop-types": 1,
    "react/jsx-uses-react": 2,
    "react/jsx-uses-vars": 2,
    "react/react-in-jsx-scope": 2,
    "react/jsx-quotes": 0,
    "react/no-multi-comp": 0,
    "react/sort-comp": 0,
    "react/jsx-closing-bracket-location": 1,
    "react/prefer-stateless-function": 1,
    "react/jsx-space-before-closing": 1,
    "jsx-quotes": 2,
    "jsx-a11y/img-uses-alt": 0,

    //
    // ES6:
    //
    "import/default": 0,
    "import/no-duplicates": 0,
    "import/named": 0,
    "import/namespace": 0,
    "import/no-unresolved": 0,
    "import/no-named-as-default": 2,
  },
  "plugins": [
    "react",
    "import"
  ],
  "settings": {
    "import/ignore": [
      "node_modules",
      "\\.(scss|less|css)$"
    ],
    "import/resolver": {
      "webpack": {
        "config": "./webpack/configForEslintImportResolver.js"
      }
    }
  },
  "globals": {
    "__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.

// snippet 1
const def = {};
const abc = [
  (''
  ),
  def,
];
def.abc = abc;
// snippet 2
const def = {};
const abc = [
  (''),
  def,
];
def.abc = abc;
// snippet 3
const def = {};
const abc = [
  '',
  def,
];
  def.abc = abc;
// snippet 4
const def = {};
const abc = {
  x: (''
  ),
  def,
};
def.abc = abc;

What did you expect to happen? Validation passes on all 4 snippets.

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

// snippet 1
const def = {};
const abc = [
  (''
  ),  // error: Bad line breaking before and after ','. (comma-style)
  def,
];
def.abc = abc;

Other snippets pass.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kaicataldocommented, Apr 30, 2016

@sompylasar Thanks!

I’ve confirmed this also happens with the default parser. Checking it out locally, it seems that the closing parens is not taken into account in snippet 1, but IS in snippet 4. This seems like a bug to me.

More specifically in snippet 1 in the original post, previousItemToken is the empty string on line 4 at this point. However, in the case of snippet 4, previousItemToken is the closing parens.

1reaction
kaicataldocommented, Apr 30, 2016

Any chance you can run ESLint on your files from the command line and share the output/confirm you’re getting the same errors?

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsonc/comma-style | eslint-plugin-jsonc
This rule enforce consistent comma style in array literals and object literals. 1. 2. 3.
Read more >
comma-style - ESLint - Pluggable JavaScript Linter
Rule Details. This rule enforce consistent comma style in array literals, object literals, and variable declarations. This rule does not apply in either...
Read more >
Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >
Code Issues
When a system is expected to behave in a certain way and it fails to meet the ... That way the array will...
Read more >
Rules
This is a summary of the standard JavaScript rules. The best way to ... Use array literals instead of array constructors. ... Only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found