Skip to content

Commit ba30df5

Browse files
authored
fix(ValidClassName): Allow upper case with number (#3497580)
1 parent 04a4563 commit ba30df5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public function process(File $phpcsFile, $stackPtr)
7474

7575
// Ensure the name is not all uppercase.
7676
// @todo We could make this more strict to check if there are more than
77-
// 2 upper case characters in a row, but not decided yet.
77+
// 2 upper case characters in a row anywhere, but not decided yet.
7878
// See https://www.drupal.org/project/coder/issues/3497433
79-
if (strtoupper($name) === $name) {
79+
if (preg_match('|^[A-Z]{3}[^a-z]*$|', $name) === 1) {
8080
$error = '%s name must use UpperCamel naming and not contain multiple upper case letters in a row';
8181
$phpcsFile->addError($error, $stackPtr, 'NoUpperAcronyms', $errorData);
8282
}

tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,19 @@ enum Test: int {
1010
// Upper case parts are allowed for now.
1111
case FourJSONCase = 4;
1212
case FiveAndAHorseCorrect = 5;
13+
case UIExample = 6;
14+
}
15+
16+
// Those are all ok.
17+
enum FiscalQuarter {
18+
case Q1;
19+
case Q2;
20+
case Q3;
21+
case Q4;
22+
}
23+
24+
enum Plan {
25+
case A;
26+
case B;
27+
case C;
1328
}

0 commit comments

Comments
 (0)