diff --git a/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php b/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php index 220d1a19..b69d2ad6 100644 --- a/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php +++ b/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php @@ -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'); } } @@ -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); @@ -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, @@ -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'); } } } @@ -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'); } } } @@ -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; @@ -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' @@ -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'); } } @@ -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, diff --git a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php index 2ebb12d4..655bd37c 100644 --- a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php +++ b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php @@ -225,7 +225,7 @@ private function validateParameterAnnotationForArgumentExists( $previousCommentClosePtr ); if ($inheritdocAnnotationWithBracesExists) { - $phpcsFile->addFixableError( + $phpcsFile->addError( '{@inheritdoc} does not import parameter annotation', $stackPtr, 'MethodArguments' @@ -233,7 +233,7 @@ private function validateParameterAnnotationForArgumentExists( } elseif ($this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr) && !$inheritdocAnnotationWithoutBracesExists ) { - $phpcsFile->addFixableError( + $phpcsFile->addError( 'Missing @param for argument in method annotation', $stackPtr, 'MethodArguments' @@ -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' @@ -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'); } } @@ -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' @@ -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' @@ -383,7 +383,7 @@ private function validateDuplicateAnnotationDoesnotExists( } } foreach ($duplicateParameters as $value) { - $phpcsFile->addFixableError( + $phpcsFile->addError( $value . ' duplicate found in method annotation', $stackPtr, 'MethodArguments' @@ -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' @@ -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' @@ -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' @@ -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' diff --git a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php index 62267ec1..d140f96c 100644 --- a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php +++ b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php @@ -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' ); } } @@ -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; } @@ -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' ); } } @@ -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' ); } } diff --git a/Magento2/Sniffs/Less/AvoidIdSniff.php b/Magento2/Sniffs/Less/AvoidIdSniff.php index d4e1b213..387b5ed8 100644 --- a/Magento2/Sniffs/Less/AvoidIdSniff.php +++ b/Magento2/Sniffs/Less/AvoidIdSniff.php @@ -51,6 +51,7 @@ class AvoidIdSniff implements Sniff T_PLUS, T_NS_SEPARATOR, T_LNUMBER, + T_BITWISE_NOT ]; /** diff --git a/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php index 3e5dbce7..1266c0dc 100644 --- a/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php +++ b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php @@ -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); } diff --git a/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc b/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc new file mode 100644 index 00000000..8124bc75 --- /dev/null +++ b/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc @@ -0,0 +1,309 @@ +productVisibility = $productVisibility; + } + + /** + * block description + * + * {@inheritdoc} + * + * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection + * @return void + */ + public function construct(AbstractDb $collection) + { + /** @var */ + $collection->setVisibility($this->productVisibility->getVisibleInCatalogIds()); + } + + /** + * Move category + * + * + * @param int $parentId new parent category id + * + * @return $this + * @throws \Magento\Framework\Exception\LocalizedException|\Exception + */ + public function move($parentId) + { + /** + * Validate new parent category id. (category model is used for backward + * compatibility in event params) + */ + try { + $this->categoryRepository->get($parentId, $this->getStoreId()); + } + catch (NoSuchEntityException $e) { + throw new \Magento\Framework\Exception\LocalizedException( + __('Sorry, but we can\'t find the new parent category you selected.'), + $e + ); + } + return true; + } + + /** + * Block for short description + * + * This a long description {@inheritdoc} consists more lines as part of the long description + * on multi line. + * + * @param int $store + * + * + */ + public function getProductListDefaultSortBy26032($store) + { + return $store; + } + + /** + * + * + * + */ + public function getProductListDefaultSortBy2632() + { + } + + /** + * Block for short description + * + * This a long description {@inheritdoc} consists more lines as part of the long description + * on multi line. + * + * @param int $store + * + * + * + */ + public function getProductListDefaultSortBy2002($store) + { + return $store; + } + + /** + * + * block for short description + * + * @param int $store + * @return int + */ + public function getProductListDefaultSortBy3002($store) + { + return $store; + } + + /** + * Block for short description + * + * @see consists more lines as part of the long description + * on multi line. + * + * @param string $store + * @param string $foo + */ + public function getProductListDefaultSortBy12($store, $foo) + { + return $store === $foo; + } + + /** + * Block for short description + * + * {@inheritdoc} + * + * @param string $store + * @param string $foo + */ + public function getProductListDefaultSort2($store, $foo) + { + return $store === $foo; + } + + /** + * Block for short description + * + * a long description {@inheritdoc} consists more lines as part of the long description + * on multi line. + * + * @param string $store + * @param string $foo + */ + public function getProductListDefault($store, $foo) + { + return $store === $foo; + } + + /** + * Retrieve custom options + * + * @param ProductOptionInterface $productOption + * + * @return array + */ + protected function getCustomOptions(ProductOptionInterface $productOption) + { + if ($productOption + && $productOption->getExtensionAttributes() + && $productOption->getExtensionAttributes()->getCustomOptions() + ) { + return $productOption->getExtensionAttributes()->getCustomOptions(); + } + return []; + } + + /** + * This is the summary for a DocBlock. + * + * This is the description for a DocBlock. This text may contain + * multiple lines and even some _markdown_. + * * Markdown style lists function too + * * Just try this out once + * The section after the description contains the tags; which provide + * structured meta-data concerning the given element. + * + * @param int $example This is an example function/method parameter description. + * @param string $example2 This is a second example. + * + */ + public function getProductListDefaultSortBy2($example, $example2) + { + return $example === $example2; + } + + /** + * Returns the content of the tokens from the specified start position in + * the token stack for the specified length. + * + * @param int $start + * @param int $length + * + * @return string The token contents. + */ + public function getProductListDefaultSortBy($start, $length) + { + return $start === $length; + } + + /** + * Some text about this step/method returns the content of the tokens the token stack for the specified length + * + * @param string $name + * @param string $folder + * + * @see this file + * @When I create a file called :name in :folder + */ + public function getProductListDefaultSortBy222($name, $folder) + { + return $name === $folder; + } + + public function setExtensionAs(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes) + { + return $this->_setExtensionAttributes($extensionAttributes); + } + + /** + * + * short description + * @param \Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes + * @return mixed + */ + public function setEn(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes) + { + return $this->_setExtensionAttributes($extensionAttributes); + } + + /** + * @param \Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes + * @return mixed + */ + public function setExtenw(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes) + { + return $this->_setExtensionAttributes($extensionAttributes); + } + + /** + * + * Short description + * @param \Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes + * @return mixed + */ + public function setExff(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes) + { + return $this->_setExtensionAttributes($extensionAttributes); + } + + /** + * {@inheritdoc} + * + * @param int $start + * @param int $length + * + * @return string The token contents. + */ + public function getProductSortBy($start, $length) + { + return $start === $length; + } +} diff --git a/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php b/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php new file mode 100644 index 00000000..8c2ac4a1 --- /dev/null +++ b/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php @@ -0,0 +1,51 @@ + 1, + 18 => 1, + 30 => 1, + 36 => 1, + 45 => 2, + 47 => 1, + 55 => 1, + 63 => 1, + 80 => 1, + 112 => 1, + 118 => 1, + 137 => 1, + 145 => 2, + 185 => 1, + 227 => 1, + 235 => 1, + 268 => 2, + 269 => 1, + 277 => 1, + 278 => 1, + 288 => 1, + 289 => 1, + 298 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} diff --git a/Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc new file mode 100644 index 00000000..f3cbbb54 --- /dev/null +++ b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc @@ -0,0 +1,24 @@ +_setExtensionAttributes($extensionAttributes); +} diff --git a/Magento2/Tests/Annotation/MethodArgumentsUnitTest.php b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.php new file mode 100644 index 00000000..623c7539 --- /dev/null +++ b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.php @@ -0,0 +1,30 @@ + 1, + 21 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} diff --git a/Magento2/Tests/Html/HtmlBindingSniffUnitTest.1.inc b/Magento2/Tests/Html/HtmlBindingUnitTest.1.inc similarity index 100% rename from Magento2/Tests/Html/HtmlBindingSniffUnitTest.1.inc rename to Magento2/Tests/Html/HtmlBindingUnitTest.1.inc diff --git a/Magento2/Tests/Html/HtmlDirectiveUnitTest.1.inc b/Magento2/Tests/Html/HtmlDirectiveUnitTest.1.inc new file mode 100644 index 00000000..250b162f --- /dev/null +++ b/Magento2/Tests/Html/HtmlDirectiveUnitTest.1.inc @@ -0,0 +1,117 @@ + + + +
{{var foo.good}}
+
{{var foo.good|stillfine}}
+
{{var foo.bad()}}
+
{{var foo.bad()|alsobad}}
+
{{var foo.getGood()}}
+
{{var foo.foo.getGood()}}
+
{{var foo.getGood().fine}}
+
{{var foo.getGood().fine|alsofine}}
+
{{var foo.bad($bad.param())}}
+
{{var foo.bad.baz()}}
+
{{var foo.undeclared.baz}}
+
{{trans "foo %bar" bar=$foo.good.trans}}
+
{{trans "foo %bar" bar=$foo.bad.trans()}}
+
{{trans "foo %bar" bar="something"}}
+
{{trans "foo %bar" bar="something" bad="$bad.bad()" something=$undeclared.var.error}}
+
{{something " + foo %barblah + " bar="something" + }}
+
{{something " + foo %barblah + " bar="something" bad=$bad.multiline() + }}
+ +{{if foo.goodif}} +
{{var foo.goodif2}}
+{{/if}} + +{{if foo.goodif}} +
{{var foo.goodif2}}
+{{else}} +
{{var foo.goodif3}}
+{{/if}} + +{{if foo.badif().bad}} +
{{var foo.badif2()}}
+{{/if}} + +{{if foo.badif3()}} +
{{var foo.badif4()}}
+{{else}} +
{{var foo.badif5()}}
+{{/if}} + +{{depend foo.gooddepend}} +
{{var foo.gooddepend2}}
+{{/depend}} + +{{depend foo.badDepend().bad}} +
{{var foo.baddepend2()}}
+{{/depend}} + +{{for item in foo.goodFor}} +
{{var foo.goodFor}}
+
{{var foo.goodFor|stillfine}}
+
{{var foo.badFor()}}
+
{{var foo.badFor()|alsobad}}
+{{/for}} + +{{for item in foo.getGoodFor()}} +
loopy
+{{/for}} + +{{for item in foo.badForLoop()}} +
this loop has a bad variable
+{{/for}} + +{{depend iusefilterslater}} +{{var iusefilterslater|raw}} +{{/depend}} diff --git a/Magento2/Tests/Html/HtmlDirectiveUnitTest.2.inc b/Magento2/Tests/Html/HtmlDirectiveUnitTest.2.inc new file mode 100644 index 00000000..6a6b222c --- /dev/null +++ b/Magento2/Tests/Html/HtmlDirectiveUnitTest.2.inc @@ -0,0 +1,12 @@ + + + +Template content doesn't matter. The JSON is invalid. diff --git a/Magento2/Tests/Html/HtmlDirectiveUnitTest.php b/Magento2/Tests/Html/HtmlDirectiveUnitTest.php new file mode 100644 index 00000000..6d7a0034 --- /dev/null +++ b/Magento2/Tests/Html/HtmlDirectiveUnitTest.php @@ -0,0 +1,33 @@ + 20]; + } elseif ($testFile === 'HtmlDirectiveUnitTest.2.inc') { + return [1 => 1]; + } + + return []; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} diff --git a/Magento2/Tests/Less/AbstractLessSniffUnitTestCase.php b/Magento2/Tests/Less/AbstractLessSniffUnitTestCase.php new file mode 100644 index 00000000..71edcbee --- /dev/null +++ b/Magento2/Tests/Less/AbstractLessSniffUnitTestCase.php @@ -0,0 +1,33 @@ +extensions = array_merge( + $config->extensions, + [ + 'less' => 'CSS' + ] + ); + + $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; + } +} diff --git a/Magento2/Tests/Less/AvoidIdUnitTest.less b/Magento2/Tests/Less/AvoidIdUnitTest.less new file mode 100644 index 00000000..070c2eec --- /dev/null +++ b/Magento2/Tests/Less/AvoidIdUnitTest.less @@ -0,0 +1,39 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +#foo[bar], +#foo[bar=bash], +#foo[bar~=bash], +#foo[bar$=bash], +#foo[bar*=bash], +#foo[bar|=bash], +#foo[bar='bash'], +#foo:hover, +#foo:nth-last-of-type(n), +#foo::before, +#foo + div, +#foo > div, +#foo ~ div, +#foo\3Abar ~ div, +#foo\:bar ~ div, +#foo.bar .baz, +div#foo { +blah: 'abc'; +} + +.my #foo, +#foo .blah, +.my #foo .blah { +some: 'stuff'; +} +.blah { +#bar .baz(); +.foo #bar .baz(); +#bar .baz(); + +#bar .baz; +.foo #bar .baz; +#bar .baz; +} diff --git a/Magento2/Tests/Less/AvoidIdUnitTest.php b/Magento2/Tests/Less/AvoidIdUnitTest.php new file mode 100644 index 00000000..33012879 --- /dev/null +++ b/Magento2/Tests/Less/AvoidIdUnitTest.php @@ -0,0 +1,46 @@ + 1, + 7 => 1, + 8 => 1, + 9 => 1, + 10 => 1, + 11 => 1, + 12 => 1, + 13 => 1, + 14 => 1, + 15 => 1, + 16 => 1, + 17 => 1, + 18 => 1, + 19 => 1, + 20 => 1, + 21 => 1, + 22 => 1, + 26 => 1, + 27 => 1, + 28 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} diff --git a/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc b/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc index 50d339a1..b3ca9957 100644 --- a/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc +++ b/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc @@ -3,4 +3,5 @@ use Magento\Tests; use Magento\Foo\Tests as FakeTest; use Magento\Real\Classes; use \Magento\{Tests\String, Tests\Int}; -use \Magento\{Foo\string, Bar\float}; \ No newline at end of file +use \Magento\{Foo\string, Bar\float}; +use \Foo\{Trailing, Space,}; \ No newline at end of file diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 3ea0c969..204946d0 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -3,7 +3,7 @@ Magento Coding Standard - + @@ -590,7 +590,9 @@ *Test.php - + + *\.less$ + 0 diff --git a/composer.json b/composer.json index d6004a88..cc1950eb 100644 --- a/composer.json +++ b/composer.json @@ -15,16 +15,18 @@ "require-dev": { "phpunit/phpunit": "^9.5.8" }, + "autoload-dev": { + "files": [ + "PHP_CodeSniffer/Tests/Standards/AbstractSniffUnitTest.php" + ] + }, "autoload": { "classmap": [ "PHP_CodeSniffer/Tokenizers/" ], "psr-4": { "Magento2\\": "Magento2/" - }, - "files": [ - "PHP_CodeSniffer/Tests/Standards/AbstractSniffUnitTest.php" - ] + } }, "scripts": { "post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..",