requireTrailingComma

Requires an extra comma following the final element of an array or object literal.

Types: Boolean or Object

Values:

  • true: validates all arrays and objects
  • Object:
    • ignoreSingleValue: allows single property objects and single element arrays to not require a trailing comma
    • ignoreSingleLine: allows objects and arrays on a single line to not require a trailing comma

Example

"requireTrailingComma": true
Valid
var foo = [1, 2, 3,];
var bar = {a: "a", b: "b",}
Valid with ignoreSingleValue
var car = [1];
var dar = {a: "a"};
Valid with ignoreSingleLine
var car = [1, 2, 3];
var dar = {a: "a", b: "b"};
Invalid
var foo = [1, 2, 3];
var bar = {a: "a", b: "b"}
Rule source
Test source