From ba30df567c9c72f9b464ad3e56f491bfa283a76b Mon Sep 17 00:00:00 2001 From: Klaus Purer <klaus.purer@protonmail.ch> Date: Sat, 11 Jan 2025 17:17:21 +0100 Subject: [PATCH] fix(ValidClassName): Allow upper case with number (#3497580) --- .../NamingConventions/ValidClassNameSniff.php | 4 ++-- .../NamingConventions/ValidEnumCaseUnitTest.inc | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php index a7df880c..0ff3a569 100644 --- a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php @@ -74,9 +74,9 @@ class ValidClassNameSniff implements Sniff // 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); } diff --git a/tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.inc b/tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.inc index b6b42807..d037f5ba 100644 --- a/tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.inc +++ b/tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.inc @@ -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; } -- GitLab