prettier / plugin-php

Prettier PHP Plugin
https://loilo.github.io/prettier-php-playground/
MIT License
1.75k stars 129 forks source link

Multi-line conditions #139

Closed mgrip closed 6 years ago

mgrip commented 6 years ago

input:

if (reallyReallyReallyLongFunction() && $this->reallyreallyreallyreallyLongMethodName()) {
  return true;
}

if ($this || $that && $theOtherThing && $someReallyReallyReallyLongBooleanVariable) {
  return true;
}

output:

if (
reallyReallyReallyLongFunction() && $this->
    reallyreallyreallyreallyLongMethodName()
) {
    return true;
}

if (
$this || $that && $theOtherThing && $someReallyReallyReallyLongBooleanVariable
) {
    return true;
}

PSR12 specifies:

Expressions in parentheses MAY be split across multiple lines, where each subsequent line is indented at least once. When doing so, the first condition MUST be on the next line. The closing parenthesis and opening brace MUST be placed together on their own line with one space between them. Boolean operators between conditions MUST always be at the beginning or at the end of the line, not a mix of both.

mgrip commented 6 years ago

interestingly prettier doesn't necessarily put each case on its own line if smaller ones fit https://prettier.io/playground/#N4Igxg9gdgLgprEAuEBLAZgAgBQCc4CGANkQJ4BKhJFVZAMtAOYBiArlGDKtNgJSYAyAZgAkMABaoAzgDp8xMvOpLFtUgyiMAsnAkQAJgDkCAWzh9+wADpRMmfDFa5bMXKzgBuGwF8bNjDhiklKYAD6hohIEMILCQXAA8hJwuAAqkpqxolIQZpQKNAX51BqMAEIQEESEUABqBLioBABG1ZY2dg5OLm6ePiAANCAQAA5c0FLIoA24EADuAAoNCJMoBABuEKj6gyAEUjDI6MRScEPNuARgANa6AMojV6iayK7uQ-oQYEcnZ2hQp1wMAWl0YJgIPyIpyGACspAAPMqXG73UxwOjPOCQ6HDVgwEZ4gBM2L+j1wgOQIGaLVIRGguxGjVgAHVthJkAAOAAMQ0ZEFOzMuI0pjLggPWWKG+AAjqxUPgQQQwRCkMcoX9TiZUK9ekMpM9GNUAIqsCDwElDGAtVn6dlIQmWy6oIgGgDCuXBlKg0ElIFYp1SLVWatO3m8QA

From what I can tell the language used in PSR12 doesn't disallow that if we can accomplish the same thing

mgrip commented 6 years ago

Ahh actually it groups together the && cases in parens and puts them on their own line

https://prettier.io/playground/#N4Igxg9gdgLgprEAuEBLAZgAgBQCc4CGANkQJ4BKhJFVZAMtAOYBiArlGDKtNgJSYAyAZgAkMABaoAzgDp8xMvOpLFtUgyiMAsnAkQAJgDkCAWzh9+wADpRMmfDFa5bMXKzgBuGwF8bNjDhiklKYAD6hohIEMILCQXAA8hJwuAAqkpqxolIQZpQKNAX51BqMAEIQEESEUABqBLioBABG1ZY2dg5OLm6ePn5QAdhB0mERQdFZ8UniKemomeHZuXDFZGuFJUwVVTX1jS1tmNa29rrdmK7uXlC+UP5YwxKjSxMxr8kzcxmMY8t5ag2G1KO2qBDqDSarTg7VOXWcl16N28IAANCAIAAHLjQKTIUANXAQADuAAUGgg8SgCAA3CCofRokAEKQwZDoYhSODo5q4AhgADWugAypj+QtGMgrtyQPoIGB2ZyZQsubgYKS+YwTARFUQueiAFZSAAeZT5gpFpjgdAWcF1+oxrBgmKdACZ7TKxbhVcgQM0WqQiNAmZjGrAAOoMiTIAAcAAZ0aGIFzw3zMb7Q3BVTS7ej8ABHViofAaghanVIDl6mVckyoKW9dFSCXVACKrAg8A96JgLUj+mjSFdPb5qCIEoAwrltb6oNBcyBWFzUi0qVWud5vEA

czosel commented 6 years ago

Fixed in #140