Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rules from phpcs.xml dosen't seem to be applied #1

Closed
nicolas-jaussaud opened this issue Feb 4, 2025 · 1 comment
Closed

Rules from phpcs.xml dosen't seem to be applied #1

nicolas-jaussaud opened this issue Feb 4, 2025 · 1 comment

Comments

@nicolas-jaussaud
Copy link

I was trying to run the roll format command of the roller (from this repository), which will then run phpBeautify if installed

While the PHP files are being formatted, it seems that they do not use our code standard set inside phpcs.xml

For example, arrays that uses the short syntax [] has been replaced by array(). If I understood correctly, it shouldn't be the case as we exclude this rule here)

The indentation is also not set to 2 space, which I think should be the case according to the rules we have here

I'm not sure what the issue is, but I tried to add -e to the command here to see what is being load, and it seems that we don't have any code standard from inside the wpcs folder:

The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz and Zend

(I saw the comment here, so maybe it's related and it's a known issue but I thought I will create an issue in case it's not the case)

@eliot-akira
Copy link
Contributor

eliot-akira commented Feb 5, 2025

Ah, good catch - I appreciate the detailed description.

I changed the tool to output the command-line arguments passed to the formatter, and confirmed that our custom rules in phpcs.xml are being loaded with the --standard option.

phpcsf -s -q --extensions=php
  --parallel=5
  --runtime-set ignore_errors_on_exit 1
  --runtime-set ignore_warnings_on_exit 1
  --runtime-set installed_paths ~/php-beautify/wpcs
  --standard=~/php-beautify/phpcs.xml
  ...files

For some reason the rules for indentation and short array syntax were still not being applied.


While trying to solve it I updated the formatter, which changed ownership since this tool was created.

And also updated the WordPress code standard rules (4de08a3). Then I searched around in the defined rules in wpcs/Universal and wpcs/WordPress to find anything related.

The solution was to disable this rule:

<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found"/>

There's no opposite rule to always use short syntax and convert array() to [], which is what I would have preferred.

For the indentation, I adjusted a few things (9783fb3) but the key change was to add:

<property name="exact" value="true"/>

That fixes indentation as expected.


The roll format command uses this PHP Beautify tool for PHP code, and Prettier for JavaScript/TypeScript and Sass. The original idea for that command was to format all our code regularly. To be honest I haven't been using it as much as I'd planned, so I'm glad to see you're trying to use it.

When I created it I was inspired by the Go language's standard formatter, which I've heard a lot of people enjoy because it removes the need to decide or discuss details of code syntax. Everyone just uses the formatter with the same rules, and the code is consistent across all projects.


I published version 1.1.0 of the NPM package @tangible/php-beautify. That should work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants