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

Single line conditions #2116

Open
arnoson opened this issue Nov 30, 2022 · 1 comment
Open

Single line conditions #2116

arnoson opened this issue Nov 30, 2022 · 1 comment

Comments

@arnoson
Copy link

arnoson commented Nov 30, 2022

When using simple conditions for early returns / guard statements the current formatting is quite verbose:

function test($arg1) {
  if (!$arg) return;

  for ($i = 0; $i < 10; $i++) {
    if ($i % 2 === 0) continue;
    // do something if the number is odd
  }
}

will be converted to:

function test($arg1) {
  if (!$arg) {
    return;
  }

  for ($i = 0; $i < 10; $i++) {
    if ($i % 2 === 0) {
      continue;
    }
    // do something if the number is odd
  }
}

It would be great if these single line conditions would be preserved. Alot of formatters for c-style languages like prettier for javascript or ClangFormat allow this, resulting in much more concise code.

@czosel
Copy link
Collaborator

czosel commented Dec 3, 2022

Hi @arnoson, thanks for reaching out about this. We chose to adhere to the PER-CS coding standard in this project as much as possible, which doesn't allow single line conditions: https://www.php-fig.org/per/coding-style/#5-control-structures
That's why I don't think this is a change we should be making, but I'll leave the issue open for further discussion.

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

No branches or pull requests

2 participants