J4 Issue ?
avatar JorSanders
JorSanders
16 Jul 2019

I want to use the official coding standard for Joomla! 4 to check my own Joomla! components.

I can't find the official coding standard anywhere for Joomla! 4 (neither the written rules or the phpcs ruleset). I found this github repo but that seems to only be the standard for Joomla! 3. At least it's the not Joomla! 4 standard. Because after running composer install it installs the ruleset to the following directory: libraries/vendor/joomla/cms-coding-standards/lib/Joomla-CMS/ruleset.xml, which is different from the one in the linked repository. So it would seem I found the correct ruleset.xml since it is included in the 4.0-dev branch. But when I try to use this ruleset by running ./libraries/vendor/bin/phpcs libraries/cms --report=checkstyle --extensions=php --encoding=utf-8 -p --standard=./libraries/vendor/joomla/cms-coding-standards/lib/Joomla-CMS. Which is the same configuration as specified in the build.xml. I get the following error:

PHP Fatal error:  Uncaught PHP_CodeSniffer_Exception: Referenced sniff "Joomla.Commenting.FileComment" does not exist in /home/jor/Projects/joomla-cms/libraries/vendor/squizlabs/php_codesniffer/CodeSniffer.php:1167

It seems to me the Joomla! rules are not installed. Which makes sense since the libraries/vendor/joomla/cms-coding-standards/lib/Joomla-CMS/ directory doesn't contain a sniffs directory which is required by phpcs to know how to enforce the rules defined in the ruleset.xml. So how do I use the.

Additionally there in the build.xml there seem to be more tools running checks on the php code:

  • PHP_Depend
  • PHPMD
  • Lint

Trying to use ant to run the build.xml is no luck as i get the same errors and more from other tools. I will spare you the output of that.

If I am missing some official Joomla! documentation where this is defined I am sorry, I did try to find documentation where this is defined.

I do see others working on fixing the codestyle so I assume others have gotten this to work on their local machine rather than see for example this Pull Request #25471

I have 3 questions:

  • where is the Joomla!4 codestyle defined?
  • how do I use phpcs with the same codestyle standards as the 4.0-dev branch uses?
  • Who maintains the codestyle standards for phpcs?

P.S. I'm not sure if i should label this as Feature Request or bug or something else on Github.

avatar JorSanders JorSanders - open - 16 Jul 2019
avatar joomla-cms-bot joomla-cms-bot - change - 16 Jul 2019
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 16 Jul 2019
avatar JorSanders JorSanders - change - 16 Jul 2019
The description was changed
avatar JorSanders JorSanders - edited - 16 Jul 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 16 Jul 2019
Labels Added: J4 Issue
avatar franz-wohlkoenig franz-wohlkoenig - labeled - 16 Jul 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 16 Jul 2019
Title
Where is Joomla! 4 codestyle documented
[4.0] Where is Joomla! 4 codestyle documented
avatar franz-wohlkoenig franz-wohlkoenig - edited - 16 Jul 2019
avatar mbabker
mbabker - comment - 16 Jul 2019

https://github.com/joomla/cms-coding-standards is an extension of https://github.com/joomla/coding-standards with some extra defaults optimized for the CMS environment (unfortunately the ruleset in the CMS standards repo really is only good out-of-the-box for this repo).

So use https://github.com/joomla/coding-standards as your base standard, and use https://github.com/joomla/cms-coding-standards to build an extended ruleset for your projects that adequately ignores things that cannot be made 100% PHPCS compliant.

avatar franz-wohlkoenig franz-wohlkoenig - edited - 16 Jul 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 16 Jul 2019
Status New Discussion
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 16 Jul 2019

@JorSanders if Issue is solved please close it.

avatar 810
810 - comment - 16 Jul 2019

@JorSanders the wait is for #25548 being merged, when it does, then your codestyle sniffer will work.

avatar JorSanders JorSanders - change - 17 Jul 2019
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2019-07-17 07:04:55
Closed_By JorSanders
avatar JorSanders
JorSanders - comment - 17 Jul 2019

@mbabker and @810 thanks for the responses this clears things up for me. I assume I will be able to setup things the way I want to now. As such closing the issue now

avatar JorSanders JorSanders - close - 17 Jul 2019

Add a Comment

Login with GitHub to post a comment