How do I resolve these JSHint ES6 errors?

I’m getting some errors from JSHint that I thought would be fixed by my settings, but they’re not.

 

“JSHint: ‘self’ is not defined. (W117)”

“JSHint: ‘console’ is not defined. (W117)”

“JSHint: ‘import’ is only available in ES6 (use ‘eversion: 6’). (W119)”

 

Also under WebStorm > Preferences > JavaScript > JavaScript language version I have ECMAScript 6 selected.

This is my .eslintrc ```

{ "root": true, "env": { "browser": true, "node": true }, "parser": "babel-eslint", "extends": "eslint:recommended", "rules": { "no-console": [0], "semi": [2, "always"] } } ```

 

I don’t know how to solve the problem.

4 comments

>“JSHint: ‘console’ is not defined. (W117)”

JSHint works on per-file basis and doesn't 'see' global variables defined in other files unless they are added to 'global' list. This can be done by either adding the corresponding comments (/* global console*/) to your code - see http://www.jshint.com/docs/, or by adding variables/functions you'd like to use globally to the Predefined list in Settings | Languages & Frameworks | JavaScript | Code Quality Tools | JSHint, Predefined (,separated)

>“JSHint: ‘import’ is only available in ES6 (use ‘eversion: 6’). (W119)”

You have to tell JSHint that your are using ES2015 syntax. This can be done by adding 

/*jshint esversion: 6 */

comment to your file (http://jshint.com/docs/options/#esversion), or by specifying

{
  "esversion": 6
}

in .jshintrc file. If you don't have your own config file, you can enable EcmaScript.next in Relaxing options in in Settings | Languages & Frameworks | JavaScript | Code Quality Tools | JSHint

 

>Also under WebStorm > Preferences > JavaScript > JavaScript language version I have ECMAScript 6 selected.

 

this option only affects WebStorm own parser and has no effect if linters are concerned

 

>This is my .eslintrc

.eslintrc is ESLint configuration file, and errors come from JSHint. These are different tools

4

How did JSHint end up in the project? I never set that up.

0

You might have it in dependencies, or configured in default project options... Anyway, if you don't like to use it, you can disable it in Settings | Languages & Frameworks | JavaScript | Code Quality Tools | JSHint

3

Elena, thank you very much. That solved my JSHint errors

1

Please sign in to leave a comment.