Skip to content
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

Allow graphql pretty formatted files #466

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to also allow white-space on the left of the name?

Suggested change
$name .= rtrim($tokens[$i]['content']);
$name .= trim($tokens[$i]['content']);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that tokenizer is never gonna create a T_STRING token with a whitespace on the left.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either fix the tokeniser to never include (leading nor) trailing whitespace in a T_STRING token, or run this through trim(). Using rtrim() seems incomplete.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation and highlighting where the extra white-space comes from (ie, the GraphQL tokeniser within this repository). Let's add a code comment here so others know why removing the trailing newline character(s) is safe in this context.

}

$valid = Common::isCamelCaps($name, true, true, false);
Expand Down
2 changes: 2 additions & 0 deletions Magento2/Tests/GraphQL/ValidTypeNameUnitTest.graphqls
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Valid type names.
type ValidCamelCaseType {}
type ValidCamelCaseTypeNewLineBrace
{}
interface ValidCamelCaseInterface {}
enum ValidCamelCaseEnum {}

Expand Down
16 changes: 8 additions & 8 deletions Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand Down