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

break statements stripped of optional number #16

Closed
nikulis opened this issue Jan 20, 2018 · 5 comments
Closed

break statements stripped of optional number #16

nikulis opened this issue Jan 20, 2018 · 5 comments
Labels

Comments

@nikulis
Copy link

nikulis commented Jan 20, 2018

I've created a new branch (nikulis/prettier-php@7ee8034) to address this, but did not want to PR at the moment since it is based on the already-open #14.


The php break statement should accept an optional trailing integer denoting the number of nested control statements to break. Currently, any trailing integer is removed.

Input:

<?php

while(true) {
  while(true) {
    break 2;
  }
}

Current output:

<?php

while(true) {
  while(true) {
    break;
  }
}

There are a couple other quirks surrounding the use of the break statement that may or may not fall under the purview of this project to auto-correct and/or offer configurable parameters for:

  1. Apparently, php also allows for parentheses around the trailing integer, making it look like a function call, e.g. break(2);. Could we automatically remove the parentheses so that all breaks follow the same convention?

  2. break 1; could be collapsed to break;.

@azz
Copy link
Member

azz commented Jan 20, 2018

Can you break $count? (I really hope not)

@nikulis
Copy link
Author

nikulis commented Jan 20, 2018

php 5.4.0 "Removed the ability to pass in variables (e.g., $num = 2; break $num;) as the numerical argument."

Which leads to the question (maybe best discussed as a separate issue): what version(s) of php will this plugin target?

@czosel
Copy link
Collaborator

czosel commented Jan 20, 2018

Nice work!
I'd suggest only targeting supported versions of PHP, i.e. 5.6 and 7.x.
About the question on parentheses: I'd prefer removing them always to enforce consistent style.

@nikulis
Copy link
Author

nikulis commented Jan 20, 2018

Agreed, and fixed in nikulis/prettier-php@da6aea4

@czosel
Copy link
Collaborator

czosel commented Feb 12, 2018

Hi @nikulis, #14 was just merged - would you like to create a PR?

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

No branches or pull requests

3 participants