-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Get different line number for attrGroups and its node #1043
Comments
samsonasik
changed the title
Make different line for attrGroups and its node
Get different line number for attrGroups and its node
Nov 23, 2024
A good heuristic would be to check the line of the name. If you want to be pedantic, get the token end position of the last attrgroup and then check whether it's followed by a newline. |
It seems I can do with: if (isset($oldTokens[$attrGroup->getEndTokenPos() + 1]) && ! str_contains((string) $oldTokens[$attrGroup->getEndTokenPos() + 1], "\n")) {
$print = $this->betterStandardPrinter->print($attrGroup);
$attributesAsComments[] = new Comment($print);
} then remove attribute, and |
Looks reasonable to me |
I found that add new line to next token seems works: if (isset($oldTokens[$attrGroup->getEndTokenPos() + 1]) && ! str_contains((string) $oldTokens[$attrGroup->getEndTokenPos() + 1], "\n")) {
// add new line
$oldTokens[$attrGroup->getEndTokenPos() + 1]->text = "\n" . $oldTokens[$attrGroup->getEndTokenPos() + 1]->text;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
currently, I can't found a way to verify the same line and different line number of code:
#[AllowDynamicProperties] class User { }
vs
#[AllowDynamicProperties]class User { }
the
getStartline()
is always equal, betweenattrGroups
vsnode
, so when downgrading, it can't be verified if it needs to be reprint or not, as in php 7, it will require get printed attrGroups and marked as comment attribute.any way to do it?
The text was updated successfully, but these errors were encountered: