Skip to content
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

Dependency graph shows nonexistent dependencies in Go #47

Open
greenled opened this issue Aug 10, 2023 · 0 comments
Open

Dependency graph shows nonexistent dependencies in Go #47

greenled opened this issue Aug 10, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@greenled
Copy link

Describe the bug
In a Go codebase, the file result dependency graph shows each .go file as depending on all .go files inside each of its imported modules, instead of only the ones with exported members used in the given file.

Describe your environment

  • Ubuntu 23.04?
  • Python 3.11.4
  • Google Chrome Version 115.0.5790.170 (Official Build) (64-bit)
  • Private repo

Here is an example output with of the program with debug (-d) flag enabled:

...
2023-08-10 11:03:26     parser D ⏩ adding import: project/pkg/somepkg/gofile1.go
2023-08-10 11:03:26     parser D ⏩ adding import: project/pkg/somepkg/gofile2_test.go
2023-08-10 11:03:26     parser D ⏩ adding import: project/pkg/somepkg/gofile3.go
2023-08-10 11:03:26     parser D ⏩ adding import: project/pkg/somepkg/gofile1_test.go
2023-08-10 11:03:26     parser D ⏩ adding import: project/pkg/somepkg/gofile2.go
...

Only project/pkg/somepkg/gofile1.go contains exported members that are used in the file being processed, but all files under project/pkg/somepkg are added as dependencies.

To Reproduce
Steps to reproduce the behavior:

  1. Create a config with at least dependency_graph and louvain_modularity scans enabled
  2. Run the tool, go to the generated HTML
  3. Open the file result dependency graph
  4. See nonexistent dependencies between some nodes

Expected behavior
I'd expect only project/pkg/somepkg/gofile1.go to be added as a dependency and to see this reflected in the visualization.

Additional context
This issue is more evident in projects with many .go files under the same packages.
Given in Go you import by package, and not by file, it may be tricky to accurately represent dependencies between files. The Go standard library provides the go/parser and go/token packages, which can be used to parse Go files and analyze their abstract syntax trees (AST). That could be helpful, but I don't know how could it fit in this Python tool.

@greenled greenled added the bug Something isn't working label Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant