0

Using Google Closure Compiler I get this error:

JSC_TRAILING_COMMA: Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. If you are targeting newer versions of JS, set the appropriate language_in option. at line 7 character 9
        },

for the following code:

App.prototype = {
    testA: function () {

    },
    testB: function () {

    },
};

I would like to know if jshint has some build-in option to detect tailing commas and show a warning message.

GibboK
  • 71,848
  • 143
  • 435
  • 658

1 Answers1

1

JSHint will warn you "Extra comma. (it breaks older versions of IE)" if you set the es3 option (in version 2.0.0 and later):

/*jshint es3: true */
var x = {
    prop1: 10,
    prop2: 20,
};

In older versions of JSHint you don't need to set the es3 option as it's the default. All versions of JSLint will also give a similar warning.

James Allardice
  • 164,175
  • 21
  • 332
  • 312
  • Thanks for your reply. Do you have any idea if it is possible to use detect "estra comma' also in jscs instead of JShint? Thanks in advance for your time. – GibboK Mar 18 '15 at 10:58
  • 1
    @GibboK - Yes, it is. Have a look at the [JSCS docs](http://jscs.info/rules.html#disallowtrailingcomma). – James Allardice Mar 18 '15 at 11:01
  • Here a related question http://stackoverflow.com/questions/29120520/disallowtrailingcomma-does-not-work-in-jscs I would really appreciate if you could have a look at it if you have time. Thanks in advance. – GibboK Mar 18 '15 at 11:13