34

Currently I'm running my tests with protractor/grunt but I'm getting the follow error message:

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

I think my .jshintrc file is not being read, because I've added this condition.

.jshintrc

{ 
  "esversion": 6 
}

Gruntfile.js

jshint : {
  all: ["tests/API/**/*.js"],
  options: {
    undef: true,
    mocha: true,
    node: true,
    jshintrc: true,
    esversion: 6,
    globals: {
      require: true,
      module: true,
      console: true,
      esversion: 6,
      }
  },
  ui: ["tests/UI/**/*.js"],
  options: {
    undef: true,
    mocha: true,
    node: true,
    jshintrc: true,
    esversion: 6,
    globals: {
      require: true,
      module: true,
      console: true,
      esversion: 6,
      jshintrc: true,
    }
  }
}

Any idea to solve this problem?

Rafael C.
  • 2,245
  • 4
  • 29
  • 45
  • Why do you use `options` and `globals` 2 times as keys if they have the same values and are in the same object depth? – GGG Mar 17 '17 at 20:06
  • 1
    What @GGG may be asking is that you have the same `options` object in your `jshint` object for no apparent reason. Are the keys `all` and `ui` supposed to be point to objects, which each have their own `options`? –  Mar 17 '17 at 20:57
  • Guys, I've removed it but my problem still occurs. – Rafael C. Mar 17 '17 at 21:11
  • This is a bit old, but have you tried settings `esnext: true` inside `options`? – GGG May 22 '17 at 05:18

5 Answers5

58

I was able to resolve this issue by adding this block of code at the top of each file.js that accused the error

/*jshint esversion: 6 */

Example:

enter image description here

Rafael C.
  • 2,245
  • 4
  • 29
  • 45
56

It is not possible to add /*jshint esversion: 6 */ in each file.js file.

Instead of above, please do below changes if you are using Visual Studio Code: -

  1. Open Visual Studio Code
  2. File -> Preferences -> Settings
  3. Default User Settings -> JSHint configuration
  4. look for "jshint.options": {},
  5. change it to "jshint.options": {"esversion": 6}, by clicking on Edit on the left
Kushal Shinde
  • 715
  • 7
  • 15
  • 3
    This worked for me. After step 3, under the config section, click "Edit in settings.json". In my settings, there was no jshint.options, so I had to add it. – JimmyV Feb 21 '19 at 15:52
18

You can do more project-specific settings by following these steps.

  1. Create a folder with the name of .vscode at the root of your project directory
  2. Create a file with the name settings.json
  3. Add the following content into it.
{
  "jshint.options": {
    "esversion": 6
  }
}

You can add some more settings to keep things consistents across your team.

{
    "editor.tabSize": 2,
    "editor.formatOnSave": true,
    "editor.formatOnType": true, 
    "jshint.options": {
        "esversion": 6
    }
}
Nadeem Yasin
  • 4,493
  • 3
  • 32
  • 41
5

Add the following into your package.json:

"jshintConfig": {
  "esversion": 6
}
Tom Hale
  • 40,825
  • 36
  • 187
  • 242
3

I have this problem after I installed JSHint. The process for me to solve this problem as below: Preference -> setting -> Extensions -> JSHint Configuration -> options -> add "jshint.options": {"esversion": 6} Done.