Skip to content

Javascript sniffer fails with function called "Function" #1191

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
gsouf opened this issue Oct 9, 2016 · 5 comments
Closed

Javascript sniffer fails with function called "Function" #1191

gsouf opened this issue Oct 9, 2016 · 5 comments

Comments

@gsouf
Copy link

gsouf commented Oct 9, 2016

Running php code sniffer on javascript file that has the function Function will detect it as the keyword function. See the example:

var a = Function('return 1+1');

Code fixer returns this error:

Expected 1 space after FUNCTION keyword; 0 found (Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction)

But this line is actually correct and there is no fix needed

@gsherwood
Copy link
Member

Just out of interest, do you actually define a function called Function or were you just looking for ways to trick the tokenizer? It would be nice to know if there is some real code that it had trouble parsing.

@gsherwood gsherwood changed the title Javascript sniffer fails with "Function"'s function Javascript sniffer fails with function called "Function" Oct 28, 2016
@gsherwood
Copy link
Member

Thanks for the report. Still keen to know if the code is real or not.

@gsouf
Copy link
Author

gsouf commented Oct 28, 2016

Hi @gsherwood yes the code is real, I'm using the javascript function Function in order to provide a way to send user defined functions from a php string to a phantomjs running webpage; https://github.com/gsouf/phantomphp/blob/master/src/phantom/page.handlers.js#L71

@gsouf
Copy link
Author

gsouf commented Oct 28, 2016

Btw thanks for the fix, I will check soon

@gsherwood
Copy link
Member

Hi @gsherwood yes the code is real

Thanks for confirming that. Please let me know if the fix doesn't work for you, although I did test the file you linked (minus the @codingStandardsIgnore comments) and confirmed the error is no longer shown.

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

2 participants