From fce7c6e231018ed09209c8014fa0b818ec3c1af6 Mon Sep 17 00:00:00 2001 From: Marc Ginesta <mginesta@adobe.com> Date: Tue, 31 Aug 2021 18:10:00 +0200 Subject: [PATCH 1/3] AC-952: Create unit test for Magento2\Less\SemicolonSpacingSniff check --- .../Tests/Less/SemicolonSpacingUnitTest.less | 13 +++++++++ .../Tests/Less/SemicolonSpacingUnitTest.php | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Magento2/Tests/Less/SemicolonSpacingUnitTest.less create mode 100644 Magento2/Tests/Less/SemicolonSpacingUnitTest.php diff --git a/Magento2/Tests/Less/SemicolonSpacingUnitTest.less b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less new file mode 100644 index 00000000..b7721cde --- /dev/null +++ b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less @@ -0,0 +1,13 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.nav { + background-color: green +} + +.bar { + background-color: red + color: white +} diff --git a/Magento2/Tests/Less/SemicolonSpacingUnitTest.php b/Magento2/Tests/Less/SemicolonSpacingUnitTest.php new file mode 100644 index 00000000..fe5d9d92 --- /dev/null +++ b/Magento2/Tests/Less/SemicolonSpacingUnitTest.php @@ -0,0 +1,27 @@ +<?php +/** + * Copyright © Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento2\Tests\Less; + +class SemicolonSpacingUnitTest extends AbstractLessSniffUnitTestCase +{ + /** + * @inheritdoc + */ + public function getErrorList() + { + return [ + 11 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 446372ac1623435627d84c385ad3fddc95f12404 Mon Sep 17 00:00:00 2001 From: Marc Ginesta <mginesta@adobe.com> Date: Wed, 1 Sep 2021 09:43:06 +0200 Subject: [PATCH 2/3] AC-952: Create unit test for Magento2\Less\SemicolonSpacingSniff check - Refactor: Fix indentation --- Magento2/Tests/Less/SemicolonSpacingUnitTest.less | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Magento2/Tests/Less/SemicolonSpacingUnitTest.less b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less index b7721cde..bf68b499 100644 --- a/Magento2/Tests/Less/SemicolonSpacingUnitTest.less +++ b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less @@ -4,10 +4,10 @@ // */ .nav { - background-color: green + background-color: green } -.bar { - background-color: red - color: white +.nav-list { + background-color: red + color: white } From 1dd90d0caded5c604733e17afd78c5f76ee17596 Mon Sep 17 00:00:00 2001 From: Marc Ginesta <mginesta@adobe.com> Date: Wed, 1 Sep 2021 17:27:17 +0200 Subject: [PATCH 3/3] AC-952: Create unit test for Magento2\Less\SemicolonSpacingSniff check - Refactor: Fix wrong index and adapt tests accordingly --- Magento2/Sniffs/Less/SemicolonSpacingSniff.php | 2 +- Magento2/Tests/Less/SemicolonSpacingUnitTest.less | 6 +++--- Magento2/Tests/Less/SemicolonSpacingUnitTest.php | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Magento2/Sniffs/Less/SemicolonSpacingSniff.php b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php index cad13290..5acc7d2e 100644 --- a/Magento2/Sniffs/Less/SemicolonSpacingSniff.php +++ b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php @@ -83,7 +83,7 @@ private function validateSemicolon(File $phpcsFile, $stackPtr, array $tokens, $s { if ((false === $semicolonPtr || $tokens[$semicolonPtr]['line'] !== $tokens[$stackPtr]['line']) && (isset($tokens[$stackPtr - 1]) && !in_array($tokens[$stackPtr - 1]['code'], $this->styleCodesToSkip)) - && (T_COLON !== $tokens[$stackPtr + 1]['code']) + && (T_COLON !== $tokens[$stackPtr]['code']) ) { $error = 'Style definitions must end with a semicolon'; $phpcsFile->addError($error, $stackPtr, 'NotAtEnd'); diff --git a/Magento2/Tests/Less/SemicolonSpacingUnitTest.less b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less index bf68b499..4c621871 100644 --- a/Magento2/Tests/Less/SemicolonSpacingUnitTest.less +++ b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less @@ -4,10 +4,10 @@ // */ .nav { - background-color: green + background-color: green; } .nav-list { - background-color: red - color: white + background-color: red ; + color: red } diff --git a/Magento2/Tests/Less/SemicolonSpacingUnitTest.php b/Magento2/Tests/Less/SemicolonSpacingUnitTest.php index fe5d9d92..e25e8d6d 100644 --- a/Magento2/Tests/Less/SemicolonSpacingUnitTest.php +++ b/Magento2/Tests/Less/SemicolonSpacingUnitTest.php @@ -13,7 +13,8 @@ class SemicolonSpacingUnitTest extends AbstractLessSniffUnitTestCase public function getErrorList() { return [ - 11 => 1 + 11 => 1, + 12 => 1 ]; }