driade / phpfmt8

PHP formatter for Sublime Text 4, with PHP 8 support.
BSD 3-Clause "New" or "Revised" License
46 stars 2 forks source link

Excluding the MergeParenCloseWithCurlyOpen option does not affect the try/catch/finally #69

Closed reprintsev closed 6 months ago

reprintsev commented 6 months ago

When using the --exclude=MergeParenCloseWithCurlyOpen option, the try/catch/finally still reformatted from

try {
    // something
}
catch (Exception $e) {
    // something
}
finally {
    // something
}

to

try {
    // something
} catch (Exception $e) {
    // something
} finally {
    // something
}
driade commented 6 months ago

Hi! What would be the expected behaviour? Please consider MergeParenCloseWithCurlyOpen is intended to work with if/else, not try/catch

driade commented 6 months ago

Sorry I finally understood your point.

MergeParenCloseWithCurlyOpen is intended to work with if/else, not try/catch, so I don't know if it'd be something to change. It's been a lot of years it behaves this way.

reprintsev commented 6 months ago

MergeParenCloseWithCurlyOpen is intended to work with if/else, not try/catch, so I don't know if it'd be something to change. It's been a lot of years it behaves this way.

Hi! I'm understood, thank you! Is it possible to add a new option for this case?

driade commented 6 months ago

I've found that the culprit for this problem is the "ResizeSpaces". I'm very sorry I can't touch this very pass to fit this need at this moment. I should add another new pass just for this specific case, and I'm currently just fixing bugs for the this package.

NormalizeLnAndLtrimLines
----
MergeParenCloseWithCurlyOpen
<?php

try {
// something
}
catch (Exception $e){
// something
}
finally {
// something
}
MergeParenCloseWithCurlyOpen
----
ResizeSpaces
<?php

try { 
// something
} catch (Exception $e) { 
// something
} finally { 
// something
}
ResizeSpaces
----
SplitCurlyCloseAndTokens
<?php