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

Files/FileName: add ability to check PSR-4-style file names #347

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Nov 20, 2023

As the Yoast plugin test directories will start to follow PSR-4. the FileName sniff will need to be able to enforce this.

This commit adds this ability to the sniff.

Notes:

  • It adds a new public psr4_paths ruleset property via the PSR4PathsTrait utility.
  • If the file being examined is in a path indicated as a PSR-4 path, PSR-4 based file names will be enforced.
  • For PSR-4 compliant file names, the file name has to match the OO name. This also means that "oo prefixes" should not be stripped and that the "excluded files" property will be ignored.
  • For non-OO files in a PSR-4 path, the normal file name rules apply, i.e. lowercase and hyphenathed and if the file contains functions, the file name should have a -functions suffix.

Includes ample tests for this new functionality.
Includes updated XML documentation.

Includes updating the YoastCS native PHPCS ruleset to enable the sniff as the YoastCS repo follows PSR-4 completely (as per the PHPCS file name rules).

👉 The changes to the pre-existing code in the sniff will be easiest to review while ignoring whitespace changes.

As the Yoast plugin test directories will start to follow PSR-4. the `FileName` sniff will need to be able to enforce this.

This commit adds this ability to the sniff.

Notes:
* It adds a new `public` `psr4_paths` ruleset property via the `PSR4PathsTrait` utility.
* If the file being examined is in a path indicated as a PSR-4 path, PSR-4 based file names will be enforced.
* For PSR-4 compliant file names, the file name has to match the OO name. This also means that "oo prefixes" should not be stripped and that the "excluded files" property will be ignored.
* For non-OO files in a PSR-4 path, the _normal_ file name rules apply, i.e. lowercase and hyphenathed and if the file contains functions, the file name should have a `-functions` suffix.

Includes ample tests for this new functionality.
Includes updated XML documentation.

Includes updating the YoastCS native PHPCS ruleset to enable the sniff as the YoastCS repo follows PSR-4 completely (as per the PHPCS file name rules).

:point_right: The changes to the pre-existing code in the sniff will be easiest to review while ignoring whitespace changes.
@coveralls
Copy link

Coverage Status

coverage: 99.423% (+0.1%) from 99.323%
when pulling 6c60a4e on JRF/filename-add-check-for-psr4-compliance
into 0d870dc on develop.

@jrfnl jrfnl merged commit 37d4b83 into develop Nov 20, 2023
25 checks passed
@jrfnl jrfnl deleted the JRF/filename-add-check-for-psr4-compliance branch November 20, 2023 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants