Skip to content

ES6 arrow function raises unexpected operator spacing errors #1265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexiscott opened this issue Jan 11, 2017 · 6 comments
Closed

ES6 arrow function raises unexpected operator spacing errors #1265

alexiscott opened this issue Jan 11, 2017 · 6 comments

Comments

@alexiscott
Copy link

alexiscott commented Jan 11, 2017

Definition of arrow function:
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Example ES6 Javascript:

var materialsLength3 = materials.map(material=> material.length);

Error raised :
1 | ERROR | [x] Expected 1 space before "="; 0 found
1 | ERROR | [x] Expected 1 space after "="; 0 found
1 | ERROR | [x] Equals sign not aligned correctly; expected 1 space but found 0 spaces
1 | ERROR | [x] Expected 1 space before ">"; 0 found

Expectation:
No error.

Other: File is OperatorSpacingSniff.php. In 3.0 ./src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php

@aik099
Copy link
Contributor

aik099 commented Jan 11, 2017

There is no much support for ES6 in general. The only features from ES6, that is correctly recognized was implemented in #1251.

@alexiscott
Copy link
Author

Thanks for your super fast response.

That is a pity, as it's being used a lot already both in documentation and with transpilers, such as Babel.

@aik099
Copy link
Contributor

aik099 commented Jan 11, 2017

Not too much I guess, since you're the 2nd person asking about this in last 2 days and before nobody asked about it. The ES6 is out there for more than 1 year if I'm not mistaken.

@gsherwood
Copy link
Member

This just needs a new token. PHP already has one for it, so I can't see this being much of a problem.

@gsherwood gsherwood changed the title ES6 arrow function raises unexpected error on master and 3.0 ES6 arrow function raises unexpected operator spacing errors Jan 11, 2017
@gsherwood
Copy link
Member

The commit adds the double arrow as a valid JS token. The sniff still reports an error because there is no space before the => operator, but it doesn't see it as two operators any more. As far as I can tell, the space before/after is used in all the arrow function specs, but please let me know if the space actually causes invalid code and I can have the sniff ignore it.

@aik099
Copy link
Contributor

aik099 commented Jan 12, 2017

Cool. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants