Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 742
Rafael C. Avatar asked Mar 17 '17 20:03

Rafael C.


People also ask

Are arrow functions ES6?

Introduction. The 2015 edition of the ECMAScript specification (ES6) added arrow function expressions to the JavaScript language. Arrow functions are a new way to write anonymous function expressions, and are similar to lambda functions in some other programming languages, such as Python.

What is the syntax of an arrow function?

Arrow Function Syntax The syntax of the arrow function is: let myFunction = (arg1, arg2, ...argN) => { statement(s) } Here, myFunction is the name of the function. arg1, arg2, ... argN are the function arguments.

Is arrow function ES5 or ES6?

The arrow function concept was introduced in ES6. With the help of this, we can write a shorter and concise syntax for a normal function which we used to write in ES5. Note: In arrow function, if there is only one statement then we don't even need to use '{}' curly braces.

Which of the following syntax is supported by ES6?

ES6 provides a feature known as Arrow Functions. It provides a more concise syntax for writing function expressions by removing the "function" and "return" keywords. Arrow functions are defined using the fat arrow ( => ) notation.


2 Answers

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

like image 178
Rafael C. Avatar answered Sep 22 '22 14:09

Rafael C.


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
like image 21
Kushal Shinde Avatar answered Sep 20 '22 14:09

Kushal Shinde