Leading and Trailing

Never use leading and trailing commas. It significantly decreases the code readability and is not compatible with the JSON notation.

Also note that trailing commas are illegal and will throw a SyntaxError when used function parameter definitions or function invocations only containing a comma. Furthermore, when using rest parameters (ES6 Rest Spread), trailing commas are not allowed:

function snow(,) {} // SyntaxError: missing formal parameter
(,) => {}; // SyntaxError: expected expression, got ','
snow(,) // SyntaxError: expected expression, got ','
function snow(...flakes,) {} // SyntaxError: parameter after rest parameter
(...flakes,) => {} // SyntaxError: expected closing parenthesis, got ','

ESLint: comma-style and comma-dangle

Examples

Incorrect code for this rule:

const winter = [
    snow
  , frost
  , ice
];
const winter = {
    name: "winter"
  , elements: ["snow", "frost", "ice"]
  , temperature: -12
  , state: "frozen"
};
const winter = [
  snow,
  frost,
  ice,
];
const winter = {
  name: "winter",
  elements: ["snow", "frost", "ice"],
  temperature: -12,
  state: "frozen",
};

Correct code for this rule:

const winter = [
  snow,
  frost,
  ice
];
const winter = {
  name: "winter",
  elements: ["snow", "frost", "ice"],
  temperature: -12,
  state: "frozen"
};

results matching ""

    No results matching ""