Nikage Nikage - 1 year ago 370
Node.js Question

jslint --edition=latest Unexpected ES6 feature. const

I'm trying to use node-jslint in order to keep my code clean

I've got a const in my nodejs script, but jslint says it isn't valid ES6 code

Unexpected ES6 feature.
const pdPersonsFilterId = process.argv[2]; // Line 10, Pos 0

Here is the command I use in the console

jslint --edition=latest index.js

According to the it possible to use global constants.

Why does jslint does not consider this code to be valid?

Answer Source

JSLint is happy enough with ES6; you just have to let it know you're using ES6. Add the es6 directive to your JSLint config or atop your file, and profit.

/*jslint es6 */
const pdPersonsFilterId = process.argv[2];

Now the warning you saw goes away.

From JSLint's help:

It may take time for the sixth edition of ECMAScript [ES6] to reach ubiquity. Using the new features in enviroments that do not fully implement the new standard will result in failure. This is why JSLint gives warnings when ES6 features are used. Some of ES6's features are good, so JSLint will recognize the good parts of ES6 with the es6 option. As implementations of the new standard become more stable and better understood, the set of features recognized by JSLint may increase. After the transition to ES6 is complete, the es6 option will be dropped. [emph mine]

Seems fair enough. So what you saw was just warning you that what you've got might not work where ES6 isn't supported, since that's a lot of places right now. Once ES6 is more widespread -- or if you explicitly let Crockford know you intend to use ES6 -- the warning will go/goes away. (TJ's point might be that, at least with Node, the time to remove the warning is now. ;^D)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download