Possibility to exclude some parts of file from formatting
Might be usefull sometimes
@pczerkas I've been thinking about this and have formed a plan that should be workable, but I was wondering if you would mind sharing some examples where this would be helpful? Or even just one example 😊
And please let me know if you have an opinion about what syntax would be appropriate to delimit sections of code that shouldn't be formatted.
@lkrms I've come up with a sound example:
having such function signature:
private function registerSql($sql, $bind = array(), $fetchMode = null, $resultType = null, $result = null)
{
[...]
I need this function (in package) to be PHP backward-compatible (so no "magic comma" is possible here), but still I want to reformat it, so it reads as:
private function registerSql(
$sql,
$bind = array(),
$fetchMode = null,
$resultType = null,
$result = null
) {
[...]
where for some other parts of the code/files I still prefer pretty-php's auto formatting.
But pretty-php reformats this function's signature back to one-liner after save (VSCode extension).
Thanks for following up, @pczerkas :)
That's an interesting example, because if you weren't using the symfony preset (which forces function/method declarations onto one line), what you're doing would work without needing to exclude anything from formatting. I'll have a think about ways this scenario could be improved for you.
Setting that aside, though, excluding a parameter list from formatting via, say, a @noformat tag in the relevant PHPDoc wouldn't be a great solution, because one would expect the rest of the method to be excluded too:
/**
* @noformat
*/
private function registerSql(
$sql,
$bind = array(),
$fetchMode = null,
$resultType = null,
$result = null
) {
[...]
So we probably need something like this instead (or in addition to the above):
// @noformat-start
private function registerSql(
$sql,
$bind = array(),
$fetchMode = null,
$resultType = null,
$result = null
) {
// @noformat-end
[...]
What do you think? Do you have a preference re: tag name? Alternatives might be:
@noFormat/@noFormatStart/@noFormatEnd@prettyphpIgnore/@prettyphpIgnoreStart/@prettyphpIgnoreEnd(similar to PHPUnit's@codeCoverageIgnoretags)@prettyphp-ignore/@prettyphp-ignore-start/@prettyphp-ignore-end
I like these: @noformat / @noformat-start / @noformat-end @prettyphp-ignore / @prettyphp-ignore-start / @prettyphp-ignore-end
all-lowercase is easier to remember ;) maybe (for the sake of easier implementation?) *-start / *-end pair would suffice?
Thx!