Haehnchen / idea-php-symfony2-plugin

IntelliJ IDEA / PhpStorm Symfony Plugin
https://plugins.jetbrains.com/plugin/7219
MIT License
913 stars 137 forks source link

Incorrect CSS Selector error when valid HTML tag is being selected #2223

Open Matt-PMCT opened 1 year ago

Matt-PMCT commented 1 year ago

When I have the Symfony Plugin enabled I am getting errors for valid $crawler->filter() calls in my unit tests.

For example, this code, which is virtually identical to the Symfony Documentation (https://symfony.com/doc/current/components/dom_crawler.html#node-traversing): $crawler->filter('h3') or $crawler->filter('body') Results in the IDE display an error stating " ':' expected " as seen in this picture: image

If I disable the Symfony Plugin, PHPStorm generates no errors, so I believe the source of it is this plugin. The code and test runs properly, so this error appears to have something to do with this plugin. The Crawler call is from this portion of Crawler.php: image

Matt-PMCT commented 10 months ago

Also, if I disable the plugin, the error goes away. I also could find no way to suppress or stop this.

After a bit of tinkering, I believe that what may be happening is that this plug-in is mistakenly classifying the variable as CSS. Then PHPpstorm says if this is CSS, then it must be proper CSS. I suspect this because if you change the string to be a proper CSS attribute with a colon and semi-colon, then PHPstorm is now happy: image

but this is not CSS; it is a selector and should not have an error.

mhujer commented 7 months ago

Just came to report same issue. It does marks invalid both HTML selectors $crawler->filter('h1') and ID selectors: $crawler->filter('#payment'). (HTML class selectors are OK $crawler->filter('.payment')).

I guess that it is because of this workaround when the parameter of filter method is wrapped so it becomes a snippet of CSS. I understand that Phpstorm probably does not have a CSS selector language available, but maybe a small adjustment to the prefix/suffix would help. When I tried adding {} to my selector, e.g. $crawler->filter('h1 {}') it made the error go away, because it is now valid CSS snippet.

https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/ad5ce2c1b3362fe1facda4e1048e5d158c053c69/src/main/java/fr/adrienbrault/idea/symfony2plugin/lang/ParameterLanguageInjector.java#L44

btw. my sidebar in controller test looks like this these days (all are selector issues): image