Skip to content

Commit 22eea72

Browse files
committed
implement acronyms
1 parent 73c7b84 commit 22eea72

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ public function process(File $phpcsFile, $stackPtr)
7272
$phpcsFile->addError($error, $stackPtr, 'NoUnderscores', $errorData);
7373
}
7474

75-
// Ensure the name is not all uppercase.
76-
if (strtoupper($name) === $name) {
77-
$error = '%s name must use UpperCamel naming and not be all uppercase';
78-
$phpcsFile->addError($error, $stackPtr, 'NotAllUppercase', $errorData);
75+
// Ensure the name does not contain acronyms.
76+
if (preg_match('|[A-Z]{2}|', $name) === 1) {
77+
$error = '%s name must use UpperCamel naming and not contain multiple upper case letters in a row';
78+
$phpcsFile->addError($error, $stackPtr, 'NoUpperAcronyms', $errorData);
7979
}
8080

8181
}//end process()
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
<?php
22

33
class CorrectClassName {}
4-
class CorrectJSONClassName {}
4+
class IncorrectJSONClassName {}
55
class INCORRECT_CLASS_NAME {}
66
class INCORRECTCLASSNAME {}
77
class incorrectLowercaseClassName {}
88

99
interface CorrectInterfaceName {}
10-
interface CorrectJSONInterfaceName {}
10+
interface IncorrectJSONInterfaceName {}
1111
interface INCORRECT_INTERFACE_NAME {}
1212
interface INCORRECTINTERFACENAME {}
1313
interface incorrectLowercaseInterfaceName {}
1414

1515
trait CorrectTraitName {}
16-
trait CorrectJSONTraitName {}
16+
trait IncorrectJSONTraitName {}
1717
trait INCORRECT_TRAIT_NAME {}
1818
trait INCORRECTTRAITNAME {}
1919
trait incorrectLowercaseTraitName {}
2020

2121
enum CorrectEnumName {}
22-
enum CorrectJSONEnumName {}
22+
enum IncorrectJSONEnumName {}
2323
enum INCORRECT_ENUM_NAME {}
2424
enum INCORRECTENUMNAME {}
2525
enum incorrectLowercaseEnumName {}

tests/Drupal/NamingConventions/ValidClassNameUnitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ class ValidClassNameUnitTest extends CoderSniffUnitTest
2121
protected function getErrorList(string $testFile): array
2222
{
2323
return [
24+
4 => 1,
2425
5 => 2,
2526
6 => 1,
2627
7 => 1,
28+
10 => 1,
2729
11 => 2,
2830
12 => 1,
2931
13 => 1,
32+
16 => 1,
3033
17 => 2,
3134
18 => 1,
3235
19 => 1,
36+
22 => 1,
3337
23 => 2,
3438
24 => 1,
3539
25 => 1,

tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ enum Test: int {
77
case TWO_TEST = 2;
88
// Must not contain only upper case.
99
case THREE = 3;
10-
// Some upper case parts are allowed for now.
10+
// Upper case parts are not allowed.
1111
case FourJSONCase = 4;
12+
case FiveCorrect = 5;
1213
}

tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ class ValidEnumCaseUnitTest extends CoderSniffUnitTest
2121
protected function getErrorList(string $testFile): array
2222
{
2323
return [
24-
5 => 1,
25-
7 => 2,
26-
9 => 1,
24+
5 => 1,
25+
7 => 2,
26+
9 => 1,
27+
11 => 1,
2728
];
2829

2930
}//end getErrorList()

0 commit comments

Comments
 (0)