DrupalEasy: Easy fix for phantom duplicate custom module files (due to Composer) in popular IDEs

When writing Drupal custom modules, best practice dictates that the module should be written in the project root's /modules/ directory - so that composer require can be used add the custom module as a dependency to the project (with a little help from the composer/installers plugin, of course). In most cases, the module's code is then symlinked from the /modules/ directory to the /web/modules/custom/ directory.

One potential pitfall of this approach is that both PhpStorm and Visual Studio Code will see both the "copies" of the files in the custom modules, leading to duplicates in IDE search results, code quality tools, and other places. 

Luckily, it is an easy fix for both PhpStorm and Visual Studio Code.

The following is an excerpt from the curriculum of Professional Module Development, a 90-hour, best-practice focused course from DrupalEasy.

Visual Studio Code

This issue can be mitigated in Visual Studio Code by navigating to "Preferences | Settings" then searching for "symlink" and disabling "Search: Follow symlinks". Note that Visual Studio Code has per-user and per-workspace (project) settings, so consider disabling this feature for one or both.
 

Image removed.

 

PhpStorm

This issue can also be mitigated in PhpStorm by marking duplicate directories as "Excluded". This can be done by right-clicking on the directory to be excluded in the project browser and selecting "Mark directory as… | Excluded". For example, to exclude the entire web/modules/custom/ directory:

Image removed.


 

PubDate

Tags