I'm trying to use node-jslint https://github.com/reid/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 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const it possible to use global constants.
Why does jslint does not consider this code to be valid?
EDIT in 2020: As ctrl-alt-delar mentions in a comment, and as predicted in the answer, JSLint has dropped the es6
requirement -- it looks like on 9 Oct 2017.
That is, es6
is no longer a valid JSLint option. The OP's code today would lint as written here:
/*jslint browser */ /*global process */ const pdPersonsFilterId = process.argv[2];
If you think you're in the OP's situation, however, ensure that whatever process you use to lint your files isn't using an older version of JSLint. Some tools ship with outdated versions, or perhaps your build script maintains an older version so as not to break legacy code. If you're in this situation, the fix below should work.
But if you know you have a version of JSLint that is newer than 9 Oct 2017 and you have what appears to be an es6 error, please open a new StackOverflow question!
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)
Try out ESLint.
It has better stats on NPM, the documentation is brilliant and it's widely used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With