Skip to content

Version 8 master update #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Magento2/Sniffs/Annotation/AnnotationFormatValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private function validateMultiLinesInShortDescription(
&& $tokens[$shortPtrEnd]['code'] !== T_DOC_COMMENT_TAG
) {
$error = 'Short description should not be in multi lines';
$phpcsFile->addFixableError($error, $shortPtrEnd + 1, 'MethodAnnotation');
$phpcsFile->addError($error, $shortPtrEnd + 1, 'MethodAnnotation');
}
}

Expand Down Expand Up @@ -95,7 +95,7 @@ private function validateSpacingBetweenShortAndLongDescriptions(
&& $tokens[$shortPtrEnd]['code'] !== T_DOC_COMMENT_TAG
) {
$error = 'There must be exactly one blank line between lines short and long descriptions';
$phpcsFile->addFixableError($error, $shortPtrEnd + 1, 'MethodAnnotation');
$phpcsFile->addError($error, $shortPtrEnd + 1, 'MethodAnnotation');
}
if ($shortPtrEnd != $shortPtr) {
$this->validateLongDescriptionFormat($phpcsFile, $shortPtrEnd, $commentEndPtr, $emptyTypeTokens);
Expand Down Expand Up @@ -123,16 +123,16 @@ private function validateShortDescriptionFormat(
$tokens = $phpcsFile->getTokens();
if ($tokens[$shortPtr]['line'] !== $tokens[$stackPtr]['line'] + 1) {
$error = 'No blank lines are allowed before short description';
$phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation');
$phpcsFile->addError($error, $shortPtr, 'MethodAnnotation');
}
if (strtolower($tokens[$shortPtr]['content']) === '{@inheritdoc}') {
$error = 'If the @inheritdoc not inline it shouldn’t have braces';
$phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation');
$phpcsFile->addError($error, $shortPtr, 'MethodAnnotation');
}
$shortPtrContent = $tokens[$shortPtr]['content'];
if (preg_match('/^\p{Ll}/u', $shortPtrContent) === 1) {
$error = 'Short description must start with a capital letter';
$phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation');
$phpcsFile->addError($error, $shortPtr, 'MethodAnnotation');
}
$this->validateNoExtraNewLineBeforeShortDescription(
$phpcsFile,
Expand Down Expand Up @@ -171,16 +171,16 @@ private function validateLongDescriptionFormat(
$longPtr = $phpcsFile->findNext($emptyTypeTokens, $shortPtrEnd + 1, $commentEndPtr - 1, true);
if (strtolower($tokens[$longPtr]['content']) === '@inheritdoc') {
$error = '@inheritdoc imports only short description, annotation must have long description';
$phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation');
$phpcsFile->addError($error, $longPtr, 'MethodAnnotation');
}
if ($longPtr !== false && $tokens[$longPtr]['code'] === T_DOC_COMMENT_STRING) {
if ($tokens[$longPtr]['line'] !== $tokens[$shortPtrEnd]['line'] + 2) {
$error = 'There must be exactly one blank line between descriptions';
$phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation');
$phpcsFile->addError($error, $longPtr, 'MethodAnnotation');
}
if (preg_match('/^\p{Ll}/u', $tokens[$longPtr]['content']) === 1) {
$error = 'Long description must start with a capital letter';
$phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation');
$phpcsFile->addError($error, $longPtr, 'MethodAnnotation');
}
}
}
Expand All @@ -203,7 +203,7 @@ public function validateTagsSpacingFormat(File $phpcsFile, int $commentStartPtr,
&& strtolower($commentTagPtrContent) !== '@inheritdoc'
) {
$error = 'There must be exactly one blank line before tags';
$phpcsFile->addFixableError($error, $firstTagPtr, 'MethodAnnotation');
$phpcsFile->addError($error, $firstTagPtr, 'MethodAnnotation');
}
}
}
Expand Down Expand Up @@ -240,7 +240,7 @@ public function validateTagGroupingFormat(File $phpcsFile, int $commentStartPtr)
if ($paramGroupId !== null
&& $paramGroupId !== $groupId) {
$error = 'Parameter tags must be grouped together';
$phpcsFile->addFixableError($error, $tag, 'MethodAnnotation');
$phpcsFile->addError($error, $tag, 'MethodAnnotation');
}
if ($paramGroupId === null) {
$paramGroupId = $groupId;
Expand Down Expand Up @@ -273,7 +273,7 @@ public function validateTagAligningFormat(File $phpcsFile, int $commentStartPtr)

if (!$this->allTagsAligned($actualPositions)
&& !$this->noneTagsAligned($actualPositions, $noAlignmentPositions)) {
$phpcsFile->addFixableError(
$phpcsFile->addError(
'Tags visual alignment must be consistent',
$stackPtr,
'MethodArguments'
Expand Down Expand Up @@ -322,7 +322,7 @@ private function validateNoExtraNewLineBeforeShortDescription(
$prevPtr = $phpcsFile->findPrevious($emptyTypeTokens, $commentEndPtr - 1, $commentStartPtr, true);
if ($tokens[$prevPtr]['line'] < ($tokens[$commentEndPtr]['line'] - 1)) {
$error = 'Additional blank lines found at end of the annotation block';
$phpcsFile->addFixableError($error, $commentEndPtr, 'MethodAnnotation');
$phpcsFile->addError($error, $commentEndPtr, 'MethodAnnotation');
}
}

Expand Down Expand Up @@ -351,7 +351,7 @@ public function validateDescriptionFormatStructure(
&& strtolower($commentTagPtrContent) !== '@inheritdoc'
) {
$error = 'Missing short description';
$phpcsFile->addFixableError($error, $commentStartPtr, 'MethodAnnotation');
$phpcsFile->addError($error, $commentStartPtr, 'MethodAnnotation');
} else {
$this->validateShortDescriptionFormat(
$phpcsFile,
Expand Down
24 changes: 12 additions & 12 deletions Magento2/Sniffs/Annotation/MethodArgumentsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ private function validateParameterAnnotationForArgumentExists(
$previousCommentClosePtr
);
if ($inheritdocAnnotationWithBracesExists) {
$phpcsFile->addFixableError(
$phpcsFile->addError(
'{@inheritdoc} does not import parameter annotation',
$stackPtr,
'MethodArguments'
);
} elseif ($this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr)
&& !$inheritdocAnnotationWithoutBracesExists
) {
$phpcsFile->addFixableError(
$phpcsFile->addError(
'Missing @param for argument in method annotation',
$stackPtr,
'MethodArguments'
Expand All @@ -257,13 +257,13 @@ private function validateCommentBlockDoesnotHaveExtraParameterAnnotation(
int $stackPtr
): void {
if ($argumentsCount < $parametersCount && $argumentsCount > 0) {
$phpcsFile->addFixableError(
$phpcsFile->addError(
'Extra @param found in method annotation',
$stackPtr,
'MethodArguments'
);
} elseif ($argumentsCount > 0 && $argumentsCount != $parametersCount && $parametersCount != 0) {
$phpcsFile->addFixableError(
$phpcsFile->addError(
'@param is not found for one or more params in method annotation',
$stackPtr,
'MethodArguments'
Expand All @@ -290,7 +290,7 @@ private function validateArgumentNameInParameterAnnotationExists(
$parameterNames = $this->getMethodParameters($paramDefinitions);
if (!in_array($methodArguments[$ptr], $parameterNames)) {
$error = $methodArguments[$ptr] . ' parameter is missing in method annotation';
$phpcsFile->addFixableError($error, $stackPtr, 'MethodArguments');
$phpcsFile->addError($error, $stackPtr, 'MethodArguments');
}
}

Expand All @@ -311,7 +311,7 @@ private function validateParameterPresentInMethodSignature(
array $paramPointers
): void {
if (!in_array($paramDefinitionsArguments, $methodArguments)) {
$phpcsFile->addFixableError(
$phpcsFile->addError(
$paramDefinitionsArguments . ' parameter is missing in method arguments signature',
$paramPointers[$ptr],
'MethodArguments'
Expand Down Expand Up @@ -340,7 +340,7 @@ private function validateParameterOrderIsCorrect(
&& in_array($methodArguments[$ptr], $parameterNames)
) {
if ($methodArguments[$ptr] != $parameterNames[$ptr]) {
$phpcsFile->addFixableError(
$phpcsFile->addError(
$methodArguments[$ptr] . ' parameter is not in order',
$paramPointers[$ptr],
'MethodArguments'
Expand Down Expand Up @@ -383,7 +383,7 @@ private function validateDuplicateAnnotationDoesnotExists(
}
}
foreach ($duplicateParameters as $value) {
$phpcsFile->addFixableError(
$phpcsFile->addError(
$value . ' duplicate found in method annotation',
$stackPtr,
'MethodArguments'
Expand All @@ -410,7 +410,7 @@ private function validateParameterAnnotationFormatIsCorrect(
): void {
switch (count($paramDefinitions)) {
case 0:
$phpcsFile->addFixableError(
$phpcsFile->addError(
'Missing both type and parameter',
$paramPointers[$ptr],
'MethodArguments'
Expand All @@ -427,7 +427,7 @@ private function validateParameterAnnotationFormatIsCorrect(
break;
case 2:
if ($this->isInvalidType($paramDefinitions[0])) {
$phpcsFile->addFixableError(
$phpcsFile->addError(
$paramDefinitions[0] . ' is not a valid PHP type',
$paramPointers[$ptr],
'MethodArguments'
Expand All @@ -449,7 +449,7 @@ private function validateParameterAnnotationFormatIsCorrect(
'MethodArguments'
);
if ($this->isInvalidType($paramDefinitions[0])) {
$phpcsFile->addFixableError(
$phpcsFile->addError(
$paramDefinitions[0] . ' is not a valid PHP type',
$paramPointers[$ptr],
'MethodArguments'
Expand Down Expand Up @@ -633,7 +633,7 @@ private function validateFormattingConsistency(
}
if (!$this->allParamsAligned($argumentPositions, $commentPositions)
&& !$this->noneParamsAligned($argumentPositions, $commentPositions, $paramDefinitions)) {
$phpcsFile->addFixableError(
$phpcsFile->addError(
'Method arguments visual alignment must be consistent',
$paramPointers[0],
'MethodArguments'
Expand Down
8 changes: 4 additions & 4 deletions Magento2/Sniffs/Html/HtmlDirectiveSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private function validateVariableUsage(File $phpcsFile, string $body): void
'Template directives may not invoke methods. Only scalar array access is allowed.' . PHP_EOL
. 'Found "' . trim($body) . '"',
null,
'HtmlTemplates.DirectiveUsage.ProhibitedMethodCall'
'HtmlTemplatesProhibitedMethodCall'
);
}
}
Expand All @@ -224,7 +224,7 @@ private function validateDefinedVariables(File $phpcsFile, string $templateText)
$phpcsFile->addError(
'Template @vars comment block contains invalid JSON.',
null,
'HtmlTemplates.DirectiveUsage.InvalidVarsJSON'
'HtmlTemplatesInvalidVarsJSON'
);
return;
}
Expand All @@ -235,7 +235,7 @@ private function validateDefinedVariables(File $phpcsFile, string $templateText)
'Template @vars comment block contains invalid label.' . PHP_EOL
. 'Label for variable "' . $var . '" is empty.',
null,
'HtmlTemplates.DirectiveUsage.InvalidVariableLabel'
'HtmlTemplatesInvalidVariableLabel'
);
}
}
Expand All @@ -254,7 +254,7 @@ private function validateDefinedVariables(File $phpcsFile, string $templateText)
'Template @vars comment block is missing a variable used in the template.' . PHP_EOL
. 'Missing variable: ' . $undefinedVariable,
null,
'HtmlTemplates.DirectiveUsage.UndefinedVariable'
'HtmlTemplatesUndefinedVariable'
);
}
}
Expand Down
1 change: 1 addition & 0 deletions Magento2/Sniffs/Less/AvoidIdSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class AvoidIdSniff implements Sniff
T_PLUS,
T_NS_SEPARATOR,
T_LNUMBER,
T_BITWISE_NOT
];

/**
Expand Down
12 changes: 7 additions & 5 deletions Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ public function process(File $phpcsFile, $stackPtr)
$closingCurly = $phpcsFile->findNext(T_CLOSE_USE_GROUP, ($next + 1));
do {
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), $closingCurly, true);
$groupedAsContent = $baseUse. $tokens[$next]['content'];
$next = $phpcsFile->findNext(T_COMMA, ($next + 1), $closingCurly);
if (strpos($groupedAsContent, $this->prohibitNamespace) !== false) {
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode);
return;
if ($next !== false) {
$groupedAsContent = $baseUse. $tokens[$next]['content'];
$next = $phpcsFile->findNext(T_COMMA, ($next + 1), $closingCurly);
if (strpos($groupedAsContent, $this->prohibitNamespace) !== false) {
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode);
return;
}
}
} while ($next !== false);
}
Expand Down
Loading