Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit a1bf55f

Browse files
committed
fix(snake_case): Sniffs trigger warnings instead of errors
1 parent 6411c6e commit a1bf55f

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
## [1.2.1] - 2021-08-25
12+
13+
### Changed
14+
15+
- Sniffs `SCS1.NamingConventions.SnakeCase*` trigger warnings instead of errors
16+
1117
## [1.2.0] - 2021-08-24
1218

1319
### Added

src/SCS1/Sniffs/NamingConventions/SnakeCaseFunctionNameSniff.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ public function processTokenOutsideScope(File $phpcsFile, $stackPtr)
2323
// Does this function claim to be magical?
2424
if (preg_match('|^__[^_]|', $functionName) !== 0) {
2525
$error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
26-
$phpcsFile->addError($error, $stackPtr, 'DoubleUnderscore', $errorData);
26+
$phpcsFile->addWarning($error, $stackPtr, 'DoubleUnderscore', $errorData);
2727

2828
$functionName = ltrim($functionName, '_');
2929
}
3030

31-
if(preg_match(',^(balise|boucle|critere|iterateur)_([a-z0-9_]+),i', $functionName, $matches)) {
31+
if (preg_match(',^(balise|boucle|critere|iterateur)_([a-z0-9_]+),i', $functionName, $matches)) {
3232
$fullName = $functionName;
3333

3434
$functionPrefix = strtolower($matches[1]);
3535
if ($functionPrefix !== $matches[1]) {
3636
$error = 'Special function name "%s" is invalid; Prefix %s must be in lowercase"';
37-
$phpcsFile->addError($error, $stackPtr, 'PrefixLowerCase', [$fullName, $functionPrefix]);
37+
$phpcsFile->addWarning($error, $stackPtr, 'PrefixLowerCase', [$fullName, $functionPrefix]);
3838
}
3939

4040
$functionName = $matches[2];
@@ -43,14 +43,14 @@ public function processTokenOutsideScope(File $phpcsFile, $stackPtr)
4343
$functionSuffix = strtolower($matches2[1]);
4444
if ($functionSuffix !== $matches2[1]) {
4545
$error = 'Special function name "%s" is invalid; Suffix %s must be in lowercase"';
46-
$phpcsFile->addError($error, $stackPtr, 'SuffixLowerCase', [$fullName, $functionSuffix]);
46+
$phpcsFile->addWarning($error, $stackPtr, 'SuffixLowerCase', [$fullName, $functionSuffix]);
4747
}
4848
}
4949

5050
if ($functionSuffix) {
5151
if ($functionPrefix !== 'balise' && $functionSuffix !== 'dist') {
5252
$error = 'Special function name "%s" is invalid; Suffix %s is not allowed with prefix %s"';
53-
$phpcsFile->addError($error, $stackPtr, 'SuffixNotAllowed', [$fullName, $functionSuffix, $functionPrefix]);
53+
$phpcsFile->addWarning($error, $stackPtr, 'SuffixNotAllowed', [$fullName, $functionSuffix, $functionPrefix]);
5454
}
5555
$functionName = preg_replace(",_$matches2[1]$,", '', $functionName);
5656
}
@@ -61,10 +61,10 @@ public function processTokenOutsideScope(File $phpcsFile, $stackPtr)
6161

6262
if ($functionName !== strtoupper($functionName)) {
6363
$error = 'Special function name "%s" is invalid; Body %s must be in uppercase"';
64-
$phpcsFile->addError($error, $stackPtr, 'ScreamingSnakeCase', [$fullName, $functionName]);
64+
$phpcsFile->addWarning($error, $stackPtr, 'ScreamingSnakeCase', [$fullName, $functionName]);
6565
}
6666
} elseif (!SnakeCase::isSnakeCase($functionName)) {
67-
$phpcsFile->addError(
67+
$phpcsFile->addWarning(
6868
'Function name "%s" is not in snake case format (Suggested name: %s)',
6969
$stackPtr,
7070
'NotSnakeCase',

src/SCS1/Sniffs/NamingConventions/SnakeCaseVariableNameSniff.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ protected function processVariable(File $phpcsFile, $stackPtr)
2020
}
2121

2222
$objOperator = $phpcsFile->findNext([T_WHITESPACE], ($stackPtr + 1), null, true);
23-
if ($tokens[$objOperator]['code'] === T_OBJECT_OPERATOR
23+
if (
24+
$tokens[$objOperator]['code'] === T_OBJECT_OPERATOR
2425
|| $tokens[$objOperator]['code'] === T_NULLSAFE_OBJECT_OPERATOR
2526
) {
2627
// Check to see if we are using a variable from an object.
@@ -42,11 +43,11 @@ protected function processVariable(File $phpcsFile, $stackPtr)
4243
$suggestedName = SnakeCase::toSnakeCase($originalVarName);
4344
$error = 'Member variable "%s" is not in valid snake_case format (Suggested name: %s)';
4445
$data = [$originalVarName, $suggestedName];
45-
$phpcsFile->addError($error, $var, 'MemberNotSnakeCase', $data);
46+
$phpcsFile->addWarning($error, $var, 'MemberNotSnakeCase', $data);
4647
}
47-
}//end if
48-
}//end if
49-
}//end if
48+
} //end if
49+
} //end if
50+
} //end if
5051

5152
$objOperator = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
5253
if ($tokens[$objOperator]['code'] === T_DOUBLE_COLON) {
@@ -61,7 +62,7 @@ protected function processVariable(File $phpcsFile, $stackPtr)
6162
$suggestedName = SnakeCase::toSnakeCase($varName);
6263
$error = 'Member variable "%s" is not in valid snake_case format (Suggested name: %s)';
6364
$data = [$tokens[$stackPtr]['content'], $suggestedName];
64-
$phpcsFile->addError($error, $stackPtr, 'MemberNotSnakeCase', $data);
65+
$phpcsFile->addWarning($error, $stackPtr, 'MemberNotSnakeCase', $data);
6566
}
6667

6768
return;
@@ -82,7 +83,7 @@ protected function processVariable(File $phpcsFile, $stackPtr)
8283
$suggestedName = SnakeCase::toSnakeCase($originalVarName);
8384
$error = 'Variable "%s" is not in valid snake case format (Suggested name: %s)';
8485
$data = [$originalVarName, $suggestedName];
85-
$phpcsFile->addError($error, $stackPtr, 'NotSnakeCase', $data);
86+
$phpcsFile->addWarning($error, $stackPtr, 'NotSnakeCase', $data);
8687
}
8788
}
8889

0 commit comments

Comments
 (0)