How to setup Eclipse to be warned about trailing comma in JavaScript
Asked Answered
T

3

9

As many of us know, IE7 is not quite friendly with JavaScript code containing trailing commas, which can be a large problem for projects using modern JS framerworks and containing a lot of JS code. In a pretty good article on the subject, the author mentions:

On the tools front, my preference for combating these devils is the Eclipse JavaScript Development Tools. The JavaScript source editor in JSDT flags trailing commas as errors: http://www.enterprisedojo.com/wp-content/uploads/2010/12/jsdtRules.png

However, using Eclipse Indigo with WTP/JSDT, I'm not seeing trailing commas as errors, and I can't find a proper setting to fix this.

How do I setup Eclipse to flag trailing commas in JavaScript as errors?

Tetrastich answered 11/9, 2011 at 22:32 Comment(1)
I would expect it to be in Preferences under JavaScript -> Validator -> Errors/Warnings with the other similar options, but it's not.Rika
R
3

It looks like the fix for another bug involving erroneous syntax errors on the comma operator also removed the syntax error on trailing commas in initializers. That's technically correct; the standard says they're allowed and IE7 is just nonconformant. There's a feature request open asking that they be reinstated.

Rika answered 25/1, 2012 at 22:33 Comment(0)
I
2

Slightly off topic, but you should also look into using JSLint to check the syntax of the JavaScript code. It will warn you about the trailing comma, but also about many other potential problems. There is a good plugin for Eclipse, http://marketplace.eclipse.org/content/phonegap-android-jslintjshint. The instructions for setting it up: http://www.mobiledevelopersolutions.com/home/announce-1/mds12released-nowwithjslintjshint

Internecine answered 13/10, 2011 at 9:38 Comment(0)
S
0

Make sure you're in the correct perspective (ie JavaScript as opposed to Java).

Also, I found in Helios that if I added a JS file to the project by right-clicking and adding a new 'File' (which I would then name with a .js extension) didn't make the UI pick up that it should be treated as a JS file--no syntax highlighting, checking, etc. If I added it specifically using the new JavaScript file option, it worked fine.

Shaffert answered 14/9, 2011 at 16:45 Comment(1)
As an aside, NetBeans will also do this for you, and I have had no problems with it not recognizing commas. I usually prefer Eclipse, but NB has gotten better recently and it works well for me when I'm doing JS development.Shaffert

© 2022 - 2024 — McMap. All rights reserved.