Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions HM/Sniffs/Files/NamespaceDirectoryNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public function process( File $phpcsFile, $stackPtr ) {
return;
}

if ( in_array( basename( dirname( $directory ) ), [ 'plugins', 'client-mu-plugins', 'mu-plugins' ], true ) ) {
if ( pathinfo( $filename, PATHINFO_FILENAME ) === basename( $directory ) ) {
// Allow plugin entrypoints named `plugin-name/plugin-name.php` instead of `plugin.php`.
return;
}
}

if ( ! preg_match( '#(?:.*)(?:/inc|/tests)(/.*)?#', $directory, $matches ) ) {
$error = 'Namespaced classes and functions should live inside an inc directory.';
$phpcsFile->addError( $error, $stackPtr, 'NoIncDirectory' );
Expand Down
3 changes: 3 additions & 0 deletions HM/Tests/Files/NamespaceDirectoryNameUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public function getErrorList() {
// Single-file mu-plugins are exempt from the directory structure rules.
'mu-plugin.php',
'client-mu-plugin.php',
// Plugin entrypoints should also allow namespace declarations.
'mypluginname.php',
'plugin.php',
];
if ( in_array( $file, $pass, true ) ) {
return [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

namespace HM\Coding\Standards\My_Plugin_Name;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

namespace HM\Coding\Standards\My_Plugin_Name;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

namespace HM\Coding\Standards\My_Plugin_Name;