pdt icon indicating copy to clipboard operation
pdt copied to clipboard

PSR-12 formatter profile

Open zulus opened this issue 4 years ago • 10 comments

Filipus Klutiero:

Although PDT comes with a formatter profile implementing the deprecated PSR-2, it does not come with one implementing the newer PSR-12 "Extended Coding Style", also recommended by the PHP-FIG (PHP Framework Interop Group), in August 2019: https://www.php-fig.org/psr/psr-12/

Such support would be welcome, as PSR-12 is more complete than PSR-2, notably regarding prefix and postfix operators.

Original bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=559386

Differences between PSR-2 nad PSR-12: https://www.php-fig.org/psr/psr-12/meta/

CodeSniffer: https://github.com/squizlabs/PHP_CodeSniffer/tree/master/src/Standards/PSR12/Sniffs

zulus avatar Jun 02 '20 12:06 zulus

Ideally PDT should be able to read phpcs.xml file (path to which would be provided by the user as configuration setting) and apply the code style rules from that file. Something similar is implemented in PHPStorm - https://www.twilio.com/blog/set-up-php-codesniffer-local-development-sublime-text-php-storm-vs-code.

Screenshot from 2020-06-02 16:26:24

bancer avatar Jun 02 '20 14:06 bancer

This task is about formatting profile, you probably thinking about something similar to #51.

zulus avatar Jun 02 '20 14:06 zulus

Yes, more or less. These issues are related. Although many projects (including ours) do not use PHP CS Fixer but use PHPCodeSniffer.

bancer avatar Jun 02 '20 14:06 bancer

Just to clarify - what I meant is an option to import phpcs.xml file that would be converted to a new Eclipse's formatter xml file. F.ex. a new button "New From phpcs.xml" here:

Screenshot from 2020-06-02 17:11:26

bancer avatar Jun 02 '20 15:06 bancer

Hi, PSR2 is deprecated since 2019, can we expect to have a PSR12 formatter profile in PDT in a future release ? VSCode and PhpStorm already have this for mounths.

haruka-7 avatar May 07 '21 21:05 haruka-7

Hey guys, any news on this one? Also, if you would need help with the coding where can I sign up?

costeaalex avatar Oct 25 '21 07:10 costeaalex

Hey guys, any news on this one? Also, if you would need help with the coding where can I sign up?

We support standard Github flow (pull requests), with one condition, you have to sign CLA. See our contribution.md

Hi, PSR2 is deprecated since 2019, can we expect to have a PSR12 formatter profile in PDT in a future release ? VSCode and PhpStorm already have this for mounths.

I'm concentrated now on PHP8 support, but formatter off course need some love ;)

zulus avatar Oct 25 '21 10:10 zulus

Hi. As I also was in search for a PSR-12 profile I finally found this one from Dolibarr: https://github.com/Dolibarr/dolibarr/blob/develop/dev/setup/eclipse/PSR-12%20%5Bbuilt-in%5D.xml

Import in Eclipse was possible. Is there any problem with this? @zulus Maybe you'd like to implement this in the next PDT version?

whatever999 avatar Jun 02 '22 01:06 whatever999

Hi. As I also was in search for a PSR-12 profile I finally found this one from Dolibarr: https://github.com/Dolibarr/dolibarr/blob/develop/dev/setup/eclipse/PSR-12%20%5Bbuilt-in%5D.xml

Import in Eclipse was possible. Is there any problem with this? @zulus Maybe you'd like to implement this in the next PDT version?

I've imported and configured the PSR-12 profile created by dolibarr. But it has no influence on 'Content Assistant' (e.g. the brackets formating is the same as before).

ungeahnt avatar Jul 31 '22 21:07 ungeahnt

Thx @ungeahnt You are right, there are no big differences between in PSR-2 and PSR-12, however it was missing and PSR-12 is the standard in many projects by now.

ATTENTION: In meanwhile I realised the guys at dolibarr have not sticked to the PSR-12 standard. In their PSR-12 profile they use tab policy = tabs. According to PSR-12 it must be be 4 spaces. (see https://www.php-fig.org/psr/psr-12/ at 2.4) I edited the dolibarr profile in Eclipse and changed: Tab policy: Spaces Identation size: 4

I suggest to do the same for the PSR-12 profile in Eclipse, if you have not yet done so.

whatever999 avatar Aug 01 '22 10:08 whatever999