jslint --edition=latest Unexpected ES6 feature. const

21,686

Solution 1

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!


For the original question/older versions of JSLint...

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)

Solution 2

Try out ESLint.

It has better stats on NPM, the documentation is brilliant and it's widely used.

Share:
21,686

Related videos on Youtube

Nikage
Author by

Nikage

Updated on September 09, 2020

Comments

  • Nikage
    Nikage over 3 years

    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?

    • mattdevio
      mattdevio about 8 years
      es6 is not 'the latest working version' of javascript.
    • Admin
      Admin about 8 years
      @magreenberg: It's not?
    • mattdevio
      mattdevio about 8 years
      No, browsers are not up to speed with the new es6 features, they are in development still. You can use them in specific cases, but are not web ready.
    • T.J. Crowder
      T.J. Crowder about 8 years
      @magreenberg: ES2015 (ES6) is indeed the latest version of JavaScript. Separately, the question above is about JavaScript code running under NodeJS. Not a browser in sight.
    • Admin
      Admin about 8 years
      @magreenberg: So they define it as some arbitrary level of browser adoption? Weird. I'd think the developer could make that determination on their own. But then it is jsLint, so I keep my expectations low.
    • Nikage
      Nikage about 8 years
      i.imgur.com/T5Q6p7j.jpg stiill does not work
    • twernt
      twernt about 8 years
      @Nikage I'd suggest ESLint for linting ES6, at least until JSLint has full support for ES6 features.
  • ruffin
    ruffin about 8 years
    @T.J.Crowder I think you have the node wrapper to blame there (there's an issue for this), not Crockford. Painfully, it looks like the node wrapper still uses JSLint from Oct 2015 for ES6, which doesn't have the es6 option. Crockford doesn't (afaik) release versions of JSLint beyond the "canonical" online version and the raw code on GitHub.
  • T.J. Crowder
    T.J. Crowder about 8 years
    I think you're right. :-) I can't imagine why I didn't twig to that.
  • Sam Mikes
    Sam Mikes about 8 years
    Wrapper now has an updated version, fwiw - but you may need --edition=es6 to work with es6 code
  • theonlygusti
    theonlygusti over 7 years
    How do I add this to a config file? (I believe the file name should be .jslintrc, but {"es6":true} does nothing)
  • mrArias
    mrArias over 6 years
    $ jslint --version node-jslint version: 0.11.0 JSLint edition 2013-08-26 With that version ES6 does not work, what the OP said holds true
  • ruffin
    ruffin over 6 years
    @mrArias What error are you receiving? What's your code? Your paste suggesets you have JSLint edition 2013-08-26 which doesn't support the es6 option, iirc. If you upgraded to a version concurrent with the question, I bet what I have above works. If you want a workaround for a 2013 edition of JSLint, you've probably got a new question. Make sense? If you can, let me know what happens when you update jslint. Also keep in mind that all es6 options are not supported in JSLint, by design, which is why seeing your code would help.
  • mrArias
    mrArias over 6 years
    Indeed it's not the same version, my bad; I got my (really old) version off a brew-installed npm; the error I got was the same as the OP: ` Unexpected ES6 feature.` Thanks!
  • ctrl-alt-delor
    ctrl-alt-delor almost 5 years
    I now get an error on the comment /*jslint es6 */ #1 Unexpected 'es6'. /*jslint es6 */ // Line 2, Pos 10
  • Andry
    Andry about 4 years
    ESLint is a much better option and MUCH better documented package.
  • ruffin
    ruffin over 3 years
    @ctrl-alt-delor Fair enough and I've updated the answer to be very specific on this point. As I mentioned, "Once ES6 is more widespread... the warning will go/goes away." The flip-side of this, however is that a version of JSLint that doesn't support the es6 option won't have the issue the OP needed resolved. If you have a new question where you think JSLint isn't recognizing an es6 feature, take a look at its howto and then feel free to create a new SO question. Hope this helps.
  • Olle Härstedt
    Olle Härstedt over 3 years
    eslint is hard to install globally.