1

I have the following line of code in an AngularJS project

$scope.listOfServices = ([].concat(...arrayOfResults.map(item =>item.data.trainServices))).filter(item => item);

This code works perfectly, however PHPStorm is kicking off saying its full of errors and it expects a new line and so on. This means on the rare occasion I reformat my code as I had a late night coding and got messy, PHPStorm moves the code around and breaks it.

I have AngularJS plugins, JavaScript plugins etc. What plugin can I install to STOP PHPStorm thinking the above line is broken.

lin
  • 17,956
  • 4
  • 59
  • 83
MOLEDesign
  • 488
  • 8
  • 20
  • `$scope.listOfServices = ([].concat(...arrayOfResults.map(item =>item.data.trainServices))).filter(item => item);` this is full of syntax errors. PHPStorm is right. – lin Feb 08 '17 at 15:04
  • Ah, fair enough.. though it doesn't throw any errors on execution. Does exactly what is required. Based on a previous SO question where I wanted to merge loads of remote data calls into a single array – MOLEDesign Feb 08 '17 at 15:35
  • If I past your line of code into my PHPStorm it shows a lot of syntax errors. The `...` isn't a JavaScript command at all. The `map` function of JavaScript is like `arr.map(callback[, thisArg])`, Yours is `arrayOfResults.map(item =>item.data.trainServices)`. If this code works, I'll eat my grandma and she is very tough... :P – lin Feb 08 '17 at 15:41
  • Start munching, this code is already in production and working perfectly to merge data from 80 separate feeds into one array. See answer where it was provided http://stackoverflow.com/questions/41675244/merge-an-array-of-arrays-in-angularjs/ – MOLEDesign Feb 08 '17 at 15:46
  • Holy crap, you are right. http://jsfiddle.net/bk8h3efa/1/ mhm in that way -1 grandma. `...` = rest operator, wow. Never saw that before. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/rest_parameters – lin Feb 08 '17 at 15:50
  • You may going to create a bug issue over here: https://youtrack.jetbrains.com/issues/WI PHPStorm supports JavaScript highlight / syntax autfill so there should be no need for a third party plugin. – lin Feb 08 '17 at 15:59
  • Thanks, if you put that as your answer, I can accept it. – MOLEDesign Feb 08 '17 at 16:00
  • Cheers m8, thanks for shown me a realy unkown operator! – lin Feb 08 '17 at 16:04

1 Answers1

1

You are right!!!

myFunction(...iterableObj); = Spread-Operator - This should be supported by PHPStorm JavaScript syntax validator.

You may going to create a bug issue over here: youtrack.jetbrains.com. PHPStorm supports JavaScript highlight / syntax autfill / validations so there should be no need for a third party plugin.

lin
  • 17,956
  • 4
  • 59
  • 83