From 45023fd7fca66789c2567760284e44ccc4719198 Mon Sep 17 00:00:00 2001 From: p-makowski Date: Wed, 13 Sep 2023 22:26:46 +0200 Subject: [PATCH 1/3] [BUGFIX] #465 Trim tokens from graphql files to allow multiline type definitions --- Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php index 602225fe..aaaae37d 100644 --- a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php @@ -32,7 +32,7 @@ public function process(File $phpcsFile, $stackPtr) //compose entity name by making use of the next strings that we find until we hit a non-string token $name = ''; for ($i=$stackPtr+1; $tokens[$i]['code'] === T_STRING; ++$i) { - $name .= $tokens[$i]['content']; + $name .= rtrim($tokens[$i]['content']); } $valid = Common::isCamelCaps($name, true, true, false); From f95a70e1172659ae80aff3a64b470bd8c13968c8 Mon Sep 17 00:00:00 2001 From: p-makowski Date: Wed, 13 Sep 2023 22:27:12 +0200 Subject: [PATCH 2/3] [BUGFIX] #465 Trim tokens from graphql files to allow multiline type definitions - unit tests adjusted --- .../Tests/GraphQL/ValidTypeNameUnitTest.graphqls | 2 ++ Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.graphqls b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.graphqls index 1fba0386..848b77d1 100644 --- a/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.graphqls +++ b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.graphqls @@ -1,5 +1,7 @@ # Valid type names. type ValidCamelCaseType {} +type ValidCamelCaseTypeNewLineBrace +{} interface ValidCamelCaseInterface {} enum ValidCamelCaseEnum {} diff --git a/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php index b1fd29b9..3948537a 100644 --- a/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php @@ -23,21 +23,21 @@ class ValidTypeNameUnitTest extends AbstractGraphQLSniffUnitTestCase protected function getErrorList() { return [ - 7 => 1, - 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, - 15 => 1, - 16 => 1, + 13 => 1, + 14 => 1, 17 => 1, - 21 => 1, + 18 => 1, + 19 => 1, 23 => 1, 25 => 1, - 35 => 1, - 39 => 1, - 43 => 1, + 27 => 1, + 37 => 1, + 41 => 1, + 45 => 1, ]; } From 93b8e207cf54967250b7d244b9c5d425f396b043 Mon Sep 17 00:00:00 2001 From: p-makowski Date: Mon, 30 Oct 2023 18:21:27 +0100 Subject: [PATCH 3/3] [CHORE] #465 Added comment about code change --- Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php index aaaae37d..83e38ed5 100644 --- a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php @@ -32,6 +32,9 @@ public function process(File $phpcsFile, $stackPtr) //compose entity name by making use of the next strings that we find until we hit a non-string token $name = ''; for ($i=$stackPtr+1; $tokens[$i]['code'] === T_STRING; ++$i) { + /** + * @see \PHP_CodeSniffer\Tokenizers\GRAPHQL::tokenize Removing EOL character artificially added to token + */ $name .= rtrim($tokens[$i]['content']); }