Skip to content

Commit

Permalink
fix(ValidClassName): Allow upper case with number (#3497580)
Browse files Browse the repository at this point in the history
  • Loading branch information
klausi authored Jan 11, 2025
1 parent 04a4563 commit ba30df5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public function process(File $phpcsFile, $stackPtr)

// Ensure the name is not all uppercase.
// @todo We could make this more strict to check if there are more than
// 2 upper case characters in a row, but not decided yet.
// 2 upper case characters in a row anywhere, but not decided yet.
// See https://www.drupal.org/project/coder/issues/3497433
if (strtoupper($name) === $name) {
if (preg_match('|^[A-Z]{3}[^a-z]*$|', $name) === 1) {
$error = '%s name must use UpperCamel naming and not contain multiple upper case letters in a row';
$phpcsFile->addError($error, $stackPtr, 'NoUpperAcronyms', $errorData);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,19 @@ enum Test: int {
// Upper case parts are allowed for now.
case FourJSONCase = 4;
case FiveAndAHorseCorrect = 5;
case UIExample = 6;
}

// Those are all ok.
enum FiscalQuarter {
case Q1;
case Q2;
case Q3;
case Q4;
}

enum Plan {
case A;
case B;
case C;
}

0 comments on commit ba30df5

Please sign in to comment.