-
Notifications
You must be signed in to change notification settings - Fork 1.5k
PHPCBF can make invalid fixes to inline JS control structures that make use of JS objects #1432
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
Comments
The problem is that the tokenizer thinks the first |
thanks @gsherwood, by saying a different sniff would find and fix that, what do you mean by that? this broke my javascript and after the sniff try to fix the code style though so i'm not at all 100% confident to run the auto code fix now. |
The sniff that detects and fixes inline control structures would find and fix this. The sniff that is causing it to break would ignore this code because the control structure doesn't have any braces. This is the code I have been testing: if ($("#myid").rotationDegrees()=='90')
$('.modal').css({'transform': 'rotate(90deg)'});
if ($("#myid").rotationDegrees()=='90')
$foo = {'transform': 'rotate(90deg)'}; And PHPCS will report these errors (note the sniff codes):
After fixing the tokenizer, you get these errors instead:
And now PHPCBF fixes the file correctly by adding braces: --- temp.js
+++ PHP_CodeSniffer
@@ -1,5 +1,7 @@
-if ($("#myid").rotationDegrees()=='90')
+if ($("#myid").rotationDegrees()=='90') {
$('.modal').css({'transform': 'rotate(90deg)'});
+}
-if ($("#myid").rotationDegrees()=='90')
+if ($("#myid").rotationDegrees()=='90') {
$foo = {'transform': 'rotate(90deg)'};
+} NOTE that this assumes your standard has included the |
…structures that make use of JS objects
I've pushed up a fix for this issue, to be included in the next 2.x and 3.x releases. Thanks for the report. |
Hello,
I ran phpcbf on the following javascript code: (notice the use of short hand, no open and close brackets which is violating psr2
and it modify the above as: (notice how phpcbf add open bracket in the if control statement but failed to add the closing bracket, also it removed bracket in the
.css
linewhich produced an javascript error exception in browser. However, if I ran phpcbf on the following (added open and close brackets and spaces)
the tools run ok.
I think this is not expected, I would expect the phpcbf to fix the above by adding opening and closing bracket in the control structure but not modifying what within it.
The text was updated successfully, but these errors were encountered: