#3681 - Run the PHP codebase through PHP_CodeSniffer beautifier
| Identifier | #3681 |
|---|---|
| Issue type | Feature request or suggestion |
| Title | Run the PHP codebase through PHP_CodeSniffer beautifier |
| Status | Completed |
| Tags |
Roadmap: v11 (custom) Type: Standards compliance (custom) |
| Handling member | Chris Graham |
| Addon | core |
| Description | Running the beautifier breaks easy merging so we need to take that into consideration. Sometimes reformatted spacing can make code harder to follow but we can fine tune the Code Sniffer config file to deal with that I think.
Attached is the rule set config file following coding standards agreed at https://compo.sr/tracker/view.php?id=1568 PHPStorm can be configured to use the rule set or a report can be generated by installing Code Sniffer using Composer `composer global require "squizlabs/php_codesniffer=*"` and running `phpcs --standard=phpcs.xml --parallel=1024`. Beautifier is `phpcbf --standard=phpcs.xml --parallel=1024`. |
| Steps to reproduce | |
| Related to | |
| Funded? | No |
The system will post a comment when this issue is modified (e.g., status changes). To be notified of this, click "Enable comment notifications".
Comments
The 'external_code_considerations' test needs to be updated to make sure exceptions coded for 3rd party libs are consistent with exceptions coded in other configuration files.
Advantages to running the formatter: closer to the code examples in the PSR-2 spec (which apparently our initial PHPStorm-based is not so much); closer to how our JS code is now formatted.
After running the formatter carefully check over the diff to make sure it's not breaking stuff.
We need to make sure the CQC still works. In particular it checks tabbing by comparing opening and closing brace positions.
I've approached this more broadly. PHP CodeSniffer and ESLint are now integrated directly into the CQC, which has also been refactored to have cleaner command line options. These tools are considered deeper checks. ESLint is not expected to have 100% passing, but PHP CodeSniffer is.
Both the PHP CodeSniffer and ESLint configurations are in git. PHP CodeSniffer has been given a PSR-12 configuration.
Additional changes have been made to the CQC so most of the PSR-12 checks can be done by the CQC itself. PHP CodeSniffer is more for very detailed text formatting stuff beyond the simple bracing and operator checks that the CQC does.
The codebook_standards document is updated to reflect PHP CodeSniffer and ESLint as official sources for code beautification and formatting guidance, as well as PSR-12.
We no longer reference PHP CS Fixer.
Running PHP CodeSniffer beautification over the codebase (at time of writing, and barring third party code) produces zero changes, as I have manually gone over to make sure it is 100% compliant.