-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Files/FileName: add ability to check PSR-4-style file names
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.
- Loading branch information
Showing
30 changed files
with
326 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
Yoast/Tests/Files/FileNameUnitTests/PSR4/Dot_Prefixed_Path.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix\\=>./PSR4 | ||
|
||
<?php | ||
|
||
class Dot_Prefixed_Path {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
8 changes: 8 additions & 0 deletions
8
Yoast/Tests/Files/FileNameUnitTests/PSR4/Illegal_PSR4_Path.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix=>PSR4/../PSR4/../ | ||
|
||
<?php | ||
|
||
class Illegal_PSR4_Path {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] PrefixA\=>Other_Path/,PrefixB=>/PSR4/,PrefixC\=>/Deep/Path/Sub/ | ||
|
||
<?php | ||
|
||
class Multiple_Paths {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix=>/PSR4/ | ||
phpcs:set Yoast.Files.FileName excluded_files_strict_check[] PSR4/Not_Excluded.inc | ||
|
||
<?php | ||
|
||
// The excluded files property should only be applied when prefix stripping is supported, which it is not for PSR4 files. | ||
class Yoast_Not_Excluded {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] | ||
// phpcs:set Yoast.Files.FileName excluded_files_strict_check[] |
11 changes: 11 additions & 0 deletions
11
Yoast/Tests/Files/FileNameUnitTests/PSR4/Prefix_Stripped.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix=>/PSR4/ | ||
phpcs:set Yoast.Files.FileName oo_prefixes[] wpseo,yoast | ||
|
||
<?php | ||
|
||
// For PSR4 file names, prefixes should *not* be stripped. | ||
class WPSEO_Prefix_Stripped {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] | ||
// phpcs:set Yoast.Files.FileName oo_prefixes[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix=>/PSR4/ | ||
|
||
<?php | ||
|
||
class Some_Class {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix\=>PSR4 | ||
|
||
<?php | ||
|
||
enum Some_Enum:int implements ArrayAccess {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix\\=>/PSR4 | ||
|
||
<?php | ||
|
||
interface Some_Interface {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix=>PSR4/ | ||
|
||
<?php | ||
|
||
TraiT Some_Trait {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
11 changes: 11 additions & 0 deletions
11
Yoast/Tests/Files/FileNameUnitTests/PSR4/WPSEO_Prefixed.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix\\=>/PSR4/ | ||
phpcs:set Yoast.Files.FileName oo_prefixes[] wpseo,yoast | ||
|
||
<?php | ||
|
||
// For PSR4 file names, prefixes should *not* be stripped. | ||
class WPSEO_Prefixed {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] | ||
// phpcs:set Yoast.Files.FileName oo_prefixes[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix=>/PSR4/ | ||
|
||
<?php | ||
|
||
class wrong_case_too {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix\\=>/PSR4/ | ||
|
||
<?php | ||
|
||
class Some_Class {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix=>PSR4 | ||
|
||
<?php | ||
|
||
enum Some_Enum:int implements ArrayAccess {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix=>/PSR4 | ||
|
||
<?php | ||
|
||
interface Some_Interface {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix=>PSR4/ | ||
|
||
<?php | ||
|
||
TraiT Some_Trait {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
11 changes: 11 additions & 0 deletions
11
Yoast/Tests/Files/FileNameUnitTests/PSR4/Yoast_Prefixed.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] PrefixA=>/src/,PrefixB=>/PSR4/ | ||
phpcs:set Yoast.Files.FileName oo_prefixes[] wpseo,yoast | ||
|
||
<?php | ||
|
||
// For PSR4 file names, prefixes should *not* be stripped. | ||
class Yoast_Prefixed {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] | ||
// phpcs:set Yoast.Files.FileName oo_prefixes[] |
8 changes: 8 additions & 0 deletions
8
Yoast/Tests/Files/FileNameUnitTests/PSR4/illegal-psr4-path.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix\\=>PSR4/../PSR4/../ | ||
|
||
<?php | ||
|
||
class Illegal_PSR4_Path {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
11 changes: 11 additions & 0 deletions
11
Yoast/Tests/Files/FileNameUnitTests/PSR4/missing-suffix.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix\\=>/PSR4/ | ||
|
||
<?php | ||
|
||
// Files without an OO structure, should follow the normal "lowercase hyphenated" + "-functions" suffix file name rules. | ||
function Foo() {} | ||
|
||
function Bar() {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
11 changes: 11 additions & 0 deletions
11
Yoast/Tests/Files/FileNameUnitTests/PSR4/no-oo-functions.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Annotation must be on line 2 as this sniff throws issues on line 1 and PHPCS ignores errors on annotation lines. --> | ||
phpcs:set Yoast.Files.FileName psr4_paths[] Prefix=>/PSR4/ | ||
|
||
<?php | ||
|
||
// Files without an OO structure, should follow the normal "lowercase hyphenated" + "-functions" suffix file name rules. | ||
function Foo() {} | ||
|
||
function Bar() {} | ||
|
||
// phpcs:set Yoast.Files.FileName psr4_paths[] |
Oops, something went wrong.