Skip to content
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

reformatting brace location can result in broken code #339

Closed
lofye opened this issue Dec 5, 2014 · 4 comments
Closed

reformatting brace location can result in broken code #339

lofye opened this issue Dec 5, 2014 · 4 comments

Comments

@lofye
Copy link

lofye commented Dec 5, 2014

in cases where you have code like this:
if($thing and $thong and $foo)
{
}

sometimes what happens is people comment out part of the conditional, like:
if($thing and $thong) // and $foo)
{
}

then when formatting is applied, and braces are brought up beside the conditional, your code becomes broken, because the opening brace is now commented out:
if($thing and $thong) // and $foo){
}

@aik099
Copy link
Contributor

aik099 commented Dec 5, 2014

So the fix might be: look for last non-comment on previous line and add { to it, right?

@gsherwood
Copy link
Member

When I test this code with all the included standards, I get the following diff:

-if($thing and $thong) // and $foo)
-{
+if ($thing and $thong) {
 }

PHPCS actually removes the commented out code and placed the brace in the correct location. Ideally, it shouldn't remove the comment because it could leave it in place, but I can't find a sniff that will add the brace to the end of the comment.

Can you let me know what standard you are using please.

@gsherwood
Copy link
Member

I've just pushed a change (548bc8d) to make the fixer code retain the comment. So you now get:

-if($thing and $thong) // and $foo)
-{
+if ($thing and $thong) {
+// and $foo)
 }

@gsherwood
Copy link
Member

If this doesn't fix your issue, please let me know.

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

3 participants