-
Notifications
You must be signed in to change notification settings - Fork 154
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
base: develop
Are you sure you want to change the base?
Allow graphql pretty formatted files #466
Conversation
…e type definitions
…e type definitions - unit tests adjusted
@@ -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']); |
There was a problem hiding this comment.
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?
$name .= rtrim($tokens[$i]['content']); | |
$name .= trim($tokens[$i]['content']); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@p-makowski please can you use a closing keyword for #465 here. |
@fredden I added issue id in my commits, so I believe issue and PR are linked already. |
Closes #465 |
Please can you put this comment into the pull request description. In order for GitHub to work its magic, the closing keyword needs to be in the commit message (not just a reference to the issue, but a closing keyword), or the pull request description (not just a comment). |
@fredden It was unclear to me when I read the documentation if it is about description, comments, commits... Edit: OK, I see now that it is linked (there is a label when I hover over the line I added to the descrpition) |
Great, thanks for your help on this @p-makowski. I can see that GitHub has linked these up, so when this pull request gets merged in, the issue will be automatically closed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is instead a bug in the tokeniser.
@@ -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']); |
There was a problem hiding this comment.
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.
@fredden see the last sentence in PR description:
EOL char is added there on purpose "otherwise PHP_CodeSniffer will screw up line numbers". Regarding trim vs. rtrim - I am not sure if I want to open additional space for regression bugs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick reply. I did miss that line in the pull request description, so thanks for highlighting it. I've reviewed the tokeniser code now, and using rtrim()
makes sense to me now.
@@ -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']); |
There was a problem hiding this comment.
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.
Code comment has been added @fredden |
Hi @fredden , any ETA on getting it out? |
@p-makowski I have no control over Adobe's release process. |
Oh, sorry @fredden! Somehow I was sure that you are part of maintaining team |
@sidolov When can we get any attention and hopefully a release? |
Currently checks for GraphQL ValidTypeName assumes that type definitions are always one-liners.
For a better readability it is much better to format GraphQL files so that they are multiline.
instead of
There can many other tags like
@doc
and in current implementation all of them have to be in one line together with type to satisfy sniff. Changes in this PR will make pretty version to pass checks.\PHP_CodeSniffer\Tokenizers\GRAPHQL::tokenize
adds\n
to token content anyway (seevendor/magento/magento-coding-standard/PHP_CodeSniffer/Tokenizers/GRAPHQL.php:134
) to not screw up with line numbers.This PR Closes #465