-
Notifications
You must be signed in to change notification settings - Fork 507
LocalTypeAliasesRule: report invalid type alias names #497
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
LocalTypeAliasesRule: report invalid type alias names #497
Conversation
bde92c7
to
730f4bd
Compare
$aliasNameResolvedType = $this->typeNodeResolver->resolve(new IdentifierTypeNode($aliasName), $nameScope->bypassTypeAliases()); | ||
if (!($aliasNameResolvedType instanceof ObjectType) | ||
&& !($aliasNameResolvedType instanceof TemplateType) // aliases take precedence over type parameters, this is reported by other rules using TemplateTypeCheck | ||
|| in_array($aliasName, ['self', 'parent'], true) |
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.
- The parentheses around
instanceof
aren't necessary,!$foo instanceof Foo
works - But I'd like parentheses disambiguating
$foo && $bar || $baz
, I honestly don't know what happens :) So there should be either($foo && $bar) || $baz
or$foo && ($bar || $baz)
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.
Ha, I guess that's some quirk of codesniffer then. When I had the disambiguating parentheses there, it reported "Useless parentheses" and since removing them helped, I didn't know it meant those parentheses around instanceof
.
BTW do we have covered also |
Now we do :) it also helped make the parentheses less messy |
b9fffc8
to
ea781c7
Compare
I had to add back the behaviour removed in e381f0b: the resolution in the rule here actually has to bypass type aliases, otherwise it would report false positives for every alias which references a non-ObjectType 😟 |
Thank you! |
follow-up of #460