akoutmos / doctor

Ensure that your Elixir project documentation is healthy
MIT License
179 stars 15 forks source link

Properly collect functions for nested modules #47

Closed randycoulman closed 2 years ago

randycoulman commented 2 years ago

Fixes #40

Thanks for this library! I've been looking for something like this for a while, and I'm glad I stumbled across it.

There were two issues:

The first issue occurred because ModuleInformation.load_user_defined_functions wasn't taking into account nested defmodule statements.

To fix this:

The second issue was caused because the modules map in Module.load_user_defined_functions was not using fully-qualified names for the nested modules. As a result, when attempting to find the nested module's functions (which uses the fully-qualified name), the module's AST wasn't found.

To fix this:

Note that nested modules can also include defimpls, so we also check for those when looking for functions.

This was the best way I could find to fix the issues with nested modules, but I'm happy to consider better solutions now that I understand the root of the problem.

I ran this version against our codebase and it fixes all of the false positives we had that were caused by this bug.

akoutmos commented 2 years ago

This is really awesome work. Thanks!