4

I'm using Composer and I don't want PhpStorm to run any error checking or inspections on the vendor folder as it is showing a false positive for some code in the vendor/composer/autoload_static.php file and hence is highlighting the lines in the file, the file itself on the left pane and it's parent folders as well all with a red underline and it's distracting.

According to this question, which is basically the issue I am having, PhpStorm isn't currently smart enough to realize this isn't actually an error.

Here is the issue from the actual file:

enter image description here

I have been trying to work out how to get PhpStorm how to ignore these folders or file and I can't seem to figure it out!?

I have tried clicking on the "little guy with the hat" at the bottom right and changing the inspection levels but it doesn't seem to make any difference.

How can I get PhpStorm to ignore these folders and get rid of the annoying red lines?

I'm using PhpStorm 2017.3

Brett
  • 19,449
  • 54
  • 157
  • 290
  • Please describe actual issue instead -- maybe there is another way of solving it (or you are trying to solve it in a wrong way). If you can provide some demo (standalone) project that would illustrate the issue -- it would be even better/ideal. – LazyOne Jan 20 '18 at 16:38
  • @LazyOne I have edited my question with more info :) – Brett Jan 20 '18 at 16:54
  • [This docs page](https://www.jetbrains.com/help/phpstorm/suppressing-inspections.html#suppress-in-editor), is that what you tried? And it didn't work? I think you would disable that given inspection for the given file, so hopefully vendor doesn't have a lot, because it looks like you have to do each one. – Jared Farrish Jan 20 '18 at 17:17
  • @JaredFarrish I actually tried clicking the light-bulb icon before but was not given the option to suppress the errors; so I tried the other option mentioned on that page by running code analysis and then selecting to suppress them, but that didn't work either; even restarted PHPStorm. – Brett Jan 20 '18 at 17:27
  • You might report that as a bug to Jet Brains, I would think that should be working in this situation. – Jared Farrish Jan 20 '18 at 17:29
  • Why do you care about `vendor/composer/autoload_static.php` file at all? Yes, if I **open** that file it will show me the errors ... but I absolutely have no need to deal with it (open it); If I run "Inspect Code" for the whole project .. it does not include it .. as `vendor/composer` is already marked as Excluded -- it does not "highlight red" on left/right side anywhere. Can you clarify this part a bit more please. – LazyOne Jan 20 '18 at 17:29
  • @LazyOne I don't care about it; but I opened it out of curiosity and that's when the error started to display and now as mentioned I can't get rid of the annoying red lines on the left pane. Would deleting the `vendor` folder and re-running `composer install` fix the issue? – Brett Jan 20 '18 at 17:33
  • @JaredFarrish I agree -- seeing highlights in Project View panel for unrelated code (3rd party library) would be super annoying. But I see **no highlights** in file explorer (Project View panel). Must be because of the way how that they are added in PhpStorm. – LazyOne Jan 20 '18 at 17:33
  • Please show screenshots for `Settings/Preferences | Directories`, `Settings/Preferences | Languages & Frameworks | PHP | Composer`, `Settings/Preferences | Languages & Frameworks | PHP` (order items in A-Z order in last one -- there is a button for that). – LazyOne Jan 20 '18 at 17:34
  • @LazyOne I don't see them either, and I can't imagine there aren't any, so there's that. – Jared Farrish Jan 20 '18 at 17:35
  • Ok, I just noticed that whilst the red lines still show in the file itself, not sure if it was the restart or suppressing the errors, but the red lines are now gone from the Project View and the `composer` folder has been marked as a 'library root'. – Brett Jan 20 '18 at 17:37
  • **In general:** if you have `Settings/Preferences | Languages & Frameworks | PHP | Composer --> Add packages as libraries` option enabled, IDE will mark all your composer packages folders as excluded (`Settings/Preferences | Directories`) .. and then re-added back as individual Include paths (`Settings/Preferences | Languages & Frameworks | PHP`) -- that's where you may see a `library root` next to them. This is enough for IDE to stop showing errors for such files in Project View panel (as such files are no longer treated as part of the project itself / not your code). – LazyOne Jan 20 '18 at 17:39
  • **The actual issue with the error highlighting**: most likely will be this one: https://youtrack.jetbrains.com/issue/WI-29871 (`Closure::bind`) – LazyOne Jan 20 '18 at 17:40
  • **In case if you still want to get rid of those "errors" even in the file itself:** just right click it (in Project View) and chose `Mark as Plain Text` -- this file will no longer be treated as PHP so no syntax checks. You could also use custom Scope (that will include such unwanted files) and disable particular inspection(s) for that scope in `Settings/Preferences | Editor | Inspections` .. but it will not work for already excluded files (as Scopes work with project files only). This can be used in other cases though where you want to have file/folder-wide inspection suppression. – LazyOne Jan 20 '18 at 17:46
  • @LazyOne Excellent - thanks for the advice. Now that the errors are gone from the project view I'm happy :) – Brett Jan 20 '18 at 17:52
  • @Brett Thanks for your clarifications. Now you see that the actual issue (that annoyed you) was not the underwaved highlighting in actual file but undervawe effect in Project View (that file and parent folders) .. especially since it's not your own code. Seeing wider (ideally whole) picture gives the ability to see the problem (and find possible solution) from a different angle. – LazyOne Jan 20 '18 at 18:11

2 Answers2

6

Issues of "Error" severity should NOT be shown in Project View panel for 3rd party code (e.g. Composer packages). The fact that they are showing -- packages are not managed in ideal way by IDE (see below) or project is not fully indexed yet.

In general: if you have Settings/Preferences | Languages & Frameworks | PHP | Composer --> Add packages as libraries option enabled, IDE will mark all your composer packages folders as excluded (Settings/Preferences | Directories) .. and then re-add them back as individual Include paths (Settings/Preferences | Languages & Frameworks | PHP) -- that's when you may see a library root text next to them. This is enough for IDE to stop showing errors for such files in Project View panel (as such files are no longer treated as part of the project code / not your code).

P.S. Even if you still see that red underwave in Project View panel .. it will disappear when you re-open the project (and will not open that file again).


The actual issue with the error highlighting: most likely will be this one: https://youtrack.jetbrains.com/issue/WI-29871 (Closure::bind).


In case if you still want to get rid of those "errors" even in the file itself: just right click it (in Project View) and chose Mark as Plain Text -- this file will no longer be treated as PHP so no syntax checks.

You could also use custom Scope (that will include such unwanted files) and disable particular inspection(s) for that scope in Settings/Preferences | Editor | Inspections .. but it will not work for already excluded files (as Scopes work with project files only). This can be used in other cases though where you want to have file/folder-wide inspection suppression.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
0

Adding an answer for PHPStorm 2023.1. As indicated in the previous answer, you can use do:

enter image description here

  • right-click on the file in the directory panel
  • Choose "Override file type"
  • Choose "Pain text"

Error will be gone. But this will also disable the PHP parsing of the file. And sometimes, you don't want to do this. So, first close the file in your editor, and undo the text type formation association:

  • right-click on the file in the directory panel
  • Choose "Revert file type Override"

Errors are gone until you reopen the file.

COil
  • 7,201
  • 2
  • 50
  • 98